tokenizing with [^;]+, why it doesn't work?
Posted: Tue Jun 10, 2008 12:15 pm
I have a sort of csv (comma separated values) file, although in this case the values are separated by semicolons. I would like to get each one of those values and put it in a cell in a table. For that I wanted to match all characters that are different from a semicolon. I've tryed with everything, preg_match, preg_match_all, and I don't even remember what more. Nothing worked...
What's wrong with it? Thanks a lot.
Code: Select all
<?php
$f = fopen("test.txt", "r");
echo '<html><body><table>';
while(!feof($f)){
echo '<tr>';
$s = fgets($f);
preg_match("/[^;]+)/", $s, $l);
for ($i = 0; $i < sizeof($l); $i++)
echo "<td>$l[i]</td>";
echo '</tr>';
}
echo '</table></body></html>';
?>