-2

preg_replaceで使用するには、配列で$withを作成する必要がありますか?

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']);

何か助けはありますか?

4

1 に答える 1

1

を使用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']);
}
于 2012-05-13T11:16:03.917 に答える