【发布时间】:2012-08-14 17:58:11
【问题描述】:
这是我的代码:
$post = $_POST['test'];
$pattren='/((([http]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\/+=&#?;%@,.\w_]*)#?(?:[\w]*)?))/';
preg_match_all( $pattren, $post, $matches);
foreach($matches[0] as $match) {
$images[]= "<a href=\"$match\" target=\"_blank\" >$match</a> ";
}
for ($i = 0, $c = count($images); $i < $c; $i++) {
$html_links = str_replace($pattren,$images[$i], $post);
}
echo $html_links;
我正在尝试从 $post 获取所有 url 并将它们转换为链接,但有问题。
【问题讨论】:
-
不应该
$pattren是$pattern吗? (哎呀,刚刚注意到 IMSoP 提到了这一点)
标签: php url hyperlink str-replace preg-match-all