I need to replace urls in the page taken by curl and add correct link. My php curl code is:
<?php
$string = '<a href="http://host.org"><img src="./sec.png"></a>';
$string = preg_replace('/href="(http:\/\/([^\/]+)\/)?([^"]+)"/', "href=\"http://google.com/\\3\"", $string);
echo $string;
?>
When the link is "a" it cut all link and left only href value.
//from
<a href="http://host.org"><img src="./sec.png"></a>
//to BUGgg when href fix make :
<a href="http://google.com/./sec.png"></a>
Can any body help in fix it.
以下preg_replace应该工作:
preg_replace('/href="(http:\/\/[^\/"]+\/?)?([^"]*)"/', "href=\"http://google.com/\\2\"", $result);
从正则表达式中删除这个不必要的部分: ([^/]+)/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.