Forum Moderators: coopster
I'd like to replace a few line of HTML which is in this pattern.
-
<li id="1"><a href></a></li>
<li id="2"><a href></a></li>
<li id="3"><a href></a></li>
<li id="4"><a href></a></li>
By using eregi("<li id=\"1">(.*)</li>", "", $page) ,
i can replace it a line by a line, but it seems very inefficient.
Is there very regular expression that can indicate a pattern like the above?
Thanks for all advices!
A part of code I'd like to remove is like this:
<li id="1"><a href="http://www.yahoo.com">Yahoo</a></li>
<li id="2"><a href="http://www.google.com">Google</a></li>
<li id="3"><a href="http://www.facebook.com">Facebook</a></li>
<li id="4"><a href="http://www.gmail.com">Gmail</a></li>
In order to remove them, the PHP code I wrote is like this:
$content = eregi_replace("<li id=\"1\">(.*)</li>", "", $content); $content = eregi_replace("<li id=\"2\">(.*)</li>", "", $content);
$content = eregi_replace("<li id=\"3\">(.*)</li>", "", $content);
$content = eregi_replace("<li id=\"4\">(.*)</li>", "", $content);
Although the above PHP code can do exactly what I want, but it seems that the code is too long.
As the content between <li>....</li> changes all the time, it's impossible to use the following code to shorten the removal process:
$content = eregi_replace("<li id=\"1\"><a href=\"http://www.yahoo.com\">Yahoo</a></li>(.*)<li id=\"4\"><a href=\"http://www.gmail.com\">Gmail</a></li>", "", $content);
What would you do to replace this?
<li id=1> .....
...............
..............
...........</li>
Any hints will be greatly appreciated.
$pattern = "<li id=\"[0-9]+\">(.*)</li>";
<?
$content="
<li id=\"1\"><a href=\"http://www.yahoo.com\">Yahoo</a></li>
<li id=\"2\"><a href=\"http://www.google.com\">Google</a></li>
<li id=\"3\"><a href=\"http://www.facebook.com\">Facebook</a></li>
<li id=\"4\"><a href=\"http://www.gmail.com\">Gmail</a></li>
<li><a href=\"www.webmastworld.com\">webmasterworld</a></li>";
echo "\$content before:<br> $content<br>";
$pattern = "/\<li\sid=\"[0-9]+\"\>(.*)\<\/li\>/";
$replacement ="replaced";
$content = preg_replace($pattern, $replacement, $content);
echo "\$content after:<br> $content";
?>