0

oh wait i just realised its that line that should have the tab parameter instead of the space

$parsedArray[] = str_getcsv($line, ' ', '"', '\\');



$parsedArray[] = str_getcsv($line, '\t', '"', '\\');

going to try that

jeth

0

i tried that code

<form method="post">
    <textarea name="ta1"></textarea>
    <input type="submit" value="Parse" name="submit" />
</form>
<?php
if(isset($_POST['ta1'])){
    $str = $_POST['ta1'];
    $str = preg_replace("/ +/", ' ', $str);
    $lines = explode("\n", $str);

    $parsedArray = array();
    foreach ($lines as $line) {
        $parsedArray[] = str_getcsv($line, '\t', '"', '\\');
    }
    //just for display
    echo "<div id='container'>";
    $x = 0;
    foreach($parsedArray as $p){
        echo "<div class='item'><pre><h3>Array Index: $x</h3>";
        print_r($p);
        echo "</pre></div>";
        $x++;
    }
    echo "</div>";
}
?>

and i got

Array Index: 0

Array
(
    [0] => 15204609 "City of Jethaya"   "'257:232"  ""  "0" "0" "0" "0" "0" "225"   "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "225"   "225 berserkers"
)
Array Index: 1

Array
(
    [0] => Total    "Total" "'" ""  "0" "0" "0" "0" "0" "225"   "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "225"   "225 berserkers"
)
Array Index: 2

Array
(
    [0] => 
)

so now it does give me my lines but doesnt seem to do the loop so my guess would be i dont have the correct symbole for tabspaces as delimiter in my str_getcsv parameters

jeth

Edited by jethaya

1

This:

$str = $_POST['ta1'];
$patterns = array("/\t+/", "/ +/"); //set up an array of items to replace
$str = preg_replace($patterns, ' ', $str);
$lines = explode("\n", $str);
0

WOOOT tanks a lot its working and i have learned a lot

final code

<?php
if(isset($_POST['TextArea1'])){
    $str = $_POST['TextArea1'];
$patterns = array("/\t+/", "/ +/"); //set up an array of items to replace
  $str = preg_replace($patterns, ' ', $str);
    $lines = explode("\n", $str);
    $parsedArray = array();
    foreach ($lines as $line) {
        $parsedArray[] = str_getcsv($line, ' ', '"', '\\');
    }
    echo "<pre>";
    print_r($parsedArray);
    echo "</pre>";
}
?>
<form method="post" >
 <textarea name="TextArea1" id="TextArea1" rows="10" cols="50"></textarea>
<input type="submit" value="Parse" name="submit" />
</form>

and the results

Array
(
    [0] => Array
        (
            [0] => 15204609
            [1] => City of Jethaya
            [2] => '257:232
            [3] => 
            [4] => 0
            [5] => 0
            [6] => 0
            [7] => 0
            [8] => 0
            [9] => 273
            [10] => 0
            [11] => 0
            [12] => 0
            [13] => 0
            [14] => 0
            [15] => 0
            [16] => 0
            [17] => 0
            [18] => 0
            [19] => 0
            [20] => 0
            [21] => 0
            [22] => 273
            [23] => 273 berserkers
        )

    [1] => Array
        (
            [0] => Total
            [1] => Total
            [2] => '
            [3] => 
            [4] => 0
            [5] => 0
            [6] => 0
            [7] => 0
            [8] => 0
            [9] => 273
            [10] => 0
            [11] => 0
            [12] => 0
            [13] => 0
            [14] => 0
            [15] => 0
            [16] => 0
            [17] => 0
            [18] => 0
            [19] => 0
            [20] => 0
            [21] => 0
            [22] => 273
            [23] => 273 berserkers
        )

)

exactly what i needed :)

jethaya

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.