如何在php中使用preg_replace函数对url进行编码?

时间:2013-08-28 14:41:31

标签: php preg-replace encode

我已遵循此代码:

$content = preg_replace('/<a href="http:\/\/domain.com\/view\/img\/(.*)">TEXT<\/a>/', '<a href="http://mydomain.com/get.php?url='.base64_encode('{$1}').'">TEXT</a>', $content);

非常感谢。

1 个答案:

答案 0 :(得分:0)

如果您使用的是PHP,我认为您必须使用“。”尝试:

$content = preg_replace('/<a href=\"http:\/\/domain.com\/view\/img\/(.*)\">TEXT<\/a>/', '<a href="http://mydomain.com/get.php?url='.base64_encode('{$1}').'">TEXT</a>', $content);