Hi,
I want to replace all the links to pages or images inside an html string. Can you please help me how can i do this with pattern matching? What should be the value (pattern matching strings) of XXX , YYY in the below egi_replace function?
For Example :-
<?php
$str_html = "Go to our<A href='index.htm'>main page</a> <br>
<img src='logo.gif' alt='logo'>Is our logo <br>
<A href='/lib/faq.htm'>faq page</a> with logo
<img src='/lib/logo.gif' alt='logo'> and others are
<A href='http://www.xyz.com/lib/other.htm'>other page</a> with
<img src='http://www.xyz.com/xyz.gif'> logo. One more is as
<A href='main/sub.htm'> </a> and give
<img src='main/sub.gif'> thats it.";
$absolute_path = "http://www.anyname.com/";
$add_before_each_href_link = "getpage.php?url_path=". $absolute_path;
$add_before_each_img_src = "getimage.php?image_path=". $absolute_path;
// What pattern matching format should i write in XXX,YYY that its shows me the below output?
$str_result = eregi_replace('XXX', 'YYY', $string);
print $str_result;
// Should result me as
/*
Go to our<A href='getpage.php?url_path=http://www.anyname.com/index.htm'>main page</a> <br>
<img src='getimage.php?image_path=http://www.anyname.com/logo.gif' alt='logo'>Is our logo <br>
<A href='getpage.php?url_path=http://www.anyname.com/lib/faq.htm'>faq page</a> with logo
<img src='getimage.php?image_path=http://www.anyname.com/lib/logo.gif' alt='logo'> and others are
<A href='getpage.php?url_path=http://www.xyz.com/lib/other.htm'>other page</a> with
<img src='getimage.php?image_path=http://www.xyz.com/xyz.gif'> logo. One more is as
<A href='getpage.php?url_path=http://www.anyname.com/main/sub.htm'> </a> and give
<img src='getimage.php?image_path=http://www.anyname.com/main/sub.gif'> thats it.";
*/
?>
Imran Khalid
imranlink@hotmail.com
PHP Developer