Reputation: 21
I have a html file which containes some links. The source code here is typically src="read.php?file=http://www.something.com/aaa/bbb/ccc/ccc.html&&someotherstring"
aaa, bbb and ccc being the only that varies, all the links are simular in structure.
I need to make this look like src="http://www.something.com/aaa/bbb/ccc/mobile.html"
I can get rid of the "read.php?file=" with str_replace, but if I try for instance explode with "/", I explode all the other "/" occurring in the html file.
Anyone got some good tips?
Upvotes: 0
Views: 38
Reputation: 13
<?php
$body="src=\"read.php?file=www.something.com/aaa/bbb/ccc/ccc.html&&someotherstring\"";
$p1=strpos($body,"read.php?file=");
$p2=strpos($body,"\"",$p1+5);
$p3=strpos($body,"&",$p1+5);
$p4=strrpos($body,"/",$p3);
$replace_str1=substr($body,$p1,$p2-$p1);
$replace_str2=substr($body,$p1+14,$p4-$p1-21)."mobile.html";
echo str_replace($body,$replace_str1,$replace_str2);
?>
may be you can try this.
Upvotes: 1