Question

i have a data, like this :

>test
AAABBB
CCCDDD
EEEFFF

I want to take one index array. if in "print_r" to be like this :

Array
(
    [0] => AAABBBCCCDDDEEEFFF
)

i have a code, like this :

$dataFQ = "data/fq.txt";

        $handleFQ = fopen($dataFQ, "r");
        if ($handleFQ)
        {
            while (($lineFQ = fgets($handleFQ, 4096)) !== false)
            {
                $lineFQ = explode("\t", $lineFQ);

                if (!empty($lineFQ[0][0]) && $lineFQ[0][0] != '>')
                {
                    $new_dataFQ[] = $lineFQ;
                }
            }
            if (!feof($handleFQ))
            {
                echo "Error: unexpected fgets() fail\n";
            }
            fclose($handleFQ);
        }
        echo '<pre>';
        print_r($new_dataFQ);
        echo '</pre>';

how to modify it in order to be an array?

Était-ce utile?

La solution

You could do in a simpler way...

<?php
$new_arr[] = implode('',(array_map('trim',array_slice(file('data/fq.txt'),1))));
print_r($new_arr);

OUTPUT :

Array
(
    [0] => AAABBBCCCDDDEEEFFF
)

Autres conseils

you can do this:

$data = file_get_content('data/fq.txt');
$trans = array('>test'=>'', "\n"=>'', "\r"=>'', ' '=>''); // and whatever you want
$result = array(strtr($data, $trans));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top