【问题标题】:prosessing a link string in php在php中处理链接字符串
【发布时间】:2015-02-15 14:03:46
【问题描述】:

我有一个包含一些链接的 html 文件。这里的源代码一般是 src="read.php?file=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 hyperlink str-replace explode


    【解决方案1】:
    <?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);
    
    ?>
    

    也许你可以试试这个。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    • 2015-05-09
    • 2012-10-08
    相关资源
    最近更新 更多