我需要在数组中制作$with才能在preg_replace中使用它?
foreach($matches[0] as $match) {
$sql = "insert into url values('$id','$match','$shorturl')";
mysql_query($sql,$con);
$with="<a href='"http://127.0.0.1/url1/". $shorturl ."'">http://127.0.0.1/". $shorturl ."</a>";
}
$html_links = preg_replace('"'b(http://'S+)"',$with , $_POST['url']);
有什么帮助吗?
您可能希望使用 preg_match_all()
,将结果保存在数组中。例:
preg_match_all("e( |s)", "the matches", $matches);
$matches
将包含所有匹配项。
有关更多详细信息,请查看文档:http://php.net/manual/en/function.preg-match-all.php
编辑:如果要将$with保存在数组中,请使用以下命令:
foreach($matches[0] as $match) {
// $sql...
// mysql...
$with[] = "<a href='"http://127.0.0.1/url1/". $shorturl ."'">http://127.0.0.1/". $shorturl ."</a>";
}
for ($w in $width) {
// do something nice with each width, using $w
$html_links = preg_replace('"'b(http://'S+)"',$w, $_POST['url']);
}