开发者

preg_replace internal link

how do I do when I want to preg_replace a href, but only if it's my own?

$a = 'href="http://mysite.com/?s=Bananas&lang=en"';
$host = 'http://mysite.com';
$a = preg_replace('#href="'.$host.'\/?[(s|p)]=([.*?])&lang=([.*?])"#e','href="index.php#$1\/$2\\lang\/$3"',$a);
//The result I want:
echo  $a;
//Becomes href="http://mysite.com/#s/Bananas\\lang/en"

But what am I doing wrong? This regex-syntax is ve开发者_StackOverflow社区ry difficult...


<?php
$a = 'href="http://mysite.com/?s=Bananas&lang=en"';
$host = 'http://mysite.com';
echo preg_replace('#href="'.preg_quote($host).'/\?(s|p)=(.*?)&lang=(.*?)"#','href="'.$host.'/#$1/$2\\\\\lang/$3"',$a);
?>

This seems to work for me :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜