在php中处理链接字符串


prosessing a link string in php

我有一个html文件,其中包含一些链接。这里的源代码通常是src="read.php"文件=http://www.something.com/aaa/bbb/ccc/ccc.html&someotherstring"

aaa、bbb和ccc是唯一变化的,所有的链接在结构上都是模拟的。

我需要让它看起来像src="http://www.something.com/aaa/bbb/ccc/mobile.html"

我可以用str_replace去掉"read.php?file=",但如果我尝试用"/"分解,我会分解html文件中出现的所有其他"/"。

有人得到一些好的建议吗?

<?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);
?>

也许你可以试试这个。