How can I take a file and delete multiple contents from it? For example, if I have the following lines in a file:
<!--1--> HTML... <!--end1--> <!--2--> HTML... <!--end2--> <!--3--> HTML... <!--end3-->
How do I delete this:
<!--2--> HTML... <!--end2-->
from the file?
$newstr=preg_replace("<!--2-->.*?<!--end2-->","",$oldstr);
more generally;
$n=2; $newstr=preg_replace("<!--".$n."-->.*?<!--end".$n."-->","",$oldstr);
-- rad
That would work, but the server I'm on uses PHP 3.0.12. Any other ideas?
i've never had to install/maintain php, so i don't know what that entails. if it's just the preg functions which are missing you could do the same with ereg, or are they missing too?
the preg_replace function is in version 3.0.9 and higher. Thats why the server I'm on dosen't have it (cause they have 3.0.12) but I can use ereg, I'm just not sure how to do multiple lines with it.
same way, except it doesn't support the ungreedy star (*?).
but so long as your tags are unique, there shouldn't be any problem.