I need to loop through a file and delete all lines starting with # I was thinking of some regex like: ^#.*\n$ will that work?
u will need to use preg match function . - read a file - declare an array - insert each line in the array - pregmatch function to see if the line begin with # - delete the line now implement it
preg match with example : http://ca.php.net/preg-match reading line and inserting them into an array : <?php if (is_readable("file.txt")) { $filecontent = file("file.txt"); echo "<ul>\n"; for ($i=0; $i < sizeof($filecontent); $i++) { echo " <li>", rtrim($filecontent[$i]), "</li>\n"; // instead of echoying , apply a method , like test (if (preg match ..) xxx , else ... } echo "</ul>\n"; } else { echo "cannot read file ...\n"; } ?> PHP: