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 :)
精彩评论