これは、誰かがメッセージボックスにテキストでリンクを張った場合にリンクをアクティブにする機能です。php link active
誰かが多くのリンクを置いた場合、私の質問は1つ以上のリンクを表示しません。例:www.yahoo.com www.gmail.com www.facebook.com次に、最初のリンクはwww.yahoo.comです
function txt2link($text){
// force http: on www.
$text = ereg_replace("www\.", "http://www.", $text);
// eliminate duplicates after force
$text = ereg_replace("http://http://www\.", "http://www.", $text);
$text = ereg_replace("https://http://www\.", "https://www.", $text);
// The Regular Expression filter
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
// Check if there is a url in the text
if(preg_match($reg_exUrl, $text, $url)) {
// make the urls hyper links
$text = preg_replace($reg_exUrl, '<a href="'.$url[0].'" rel="nofollow">'.$url[0].'</a>', $text);
} // if no urls in the text just return the text
return ($text);
}
$url = "Alter pot waer it your pot http://css-tricks.com/snippets/php/find-urls-in-
text-make-links/ you may click the link www.yahoo.com or you may see what is the
http://www.youtube.com say, is it right?";
echo txt2link($url);
このコードを実行すると、結果を確認できます。
私はそれを取得しません。今日だけでも、私はテキストからURLを抽出しようとしている(しかし異なる!)正規表現を持つ十数人を見ました。なぜこれが起こるのですか? PHPの 'get_urls'パッケージの開発者は、お金でいっぱいのプールで泳ぐでしょうか? – Borealid
私が言う最初のことは、プリグに賛成して逃げようとしていることです、それはしばらくの間非難されています。 – quickshiftin
jsを使ってこのクライアントサイトをやってみたことがありますか? http://benalman.com/code/projects/javascript-linkify/docs/files/ba-linkify-js.html – Flukey