curl-and-php
pattren matching eregi_replace
Date: Thu, 03 Jun 2004 05:17:29 +0000
HI,
Actually i am trying write a script that open web sites pages with images
those are not opening in other regions. for example a site www.anyname.com
is not opening on my ISP but is opening on my Web server. So i will use CURL
on my webserver to fetch and show this site page contents and images.
Further more i want to link all the links to ther pages goes from my CURL
script.
www.script.com/myscript.php?url_to_open=www.anyname.com
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 :-
[code]
//////////////////////////////////////////////////////////////////////////////////////
<?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.";
*/
//////////////////////////////////////////////////////////////////////////////////////
?>
[/code]
Imran Khalid
imranlink_at_hotmail.com
PHP Developer
_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail
Received on 2004-06-03