http:// を含むワードが入力されたら自動的にそのリンクを作成するfunctionを作成してください。
例:
http://www.yahoo.com/が入力されたら <a href="http://www.yahoo.com/" target="_blank">http://www.yahoo.com/</a> というリンクを作成する。
PHPのドキュメントにもサンプルがあります。24-May-2006 10:58のSune Rievers氏のサンプルなどが参考になるのでは?
基本的にはそのまま使えますよ。
function make_links_blank($text) { return preg_replace( array( '/(?(?=<a[^>]*>.+<\/a>) (?:<a[^>]*>.+<\/a>) | ([^="\']?)((?:https?|ftp|bf2|):\/\/[^<> \n\r]+) )/iex', '/<a([^>]*)target="?[^"\']+"?/i', '/<a([^>]+)>/i', '/(^|\s)(www.[^<> \n\r]+)/iex', '/(([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-]+) (\\.[A-Za-z0-9-]+)*)/iex' ), array( "stripslashes((strlen('\\2')>0?'\\1<a href=\"\\2\">\\2</a>\\3':'\\0'))", '<a\\1', '<a\\1 target="_blank">', "stripslashes((strlen('\\2')>0?'\\1<a href=\"http://\\2\">\\2</a>\\3':'\\0'))", "stripslashes((strlen('\\2')>0?'<a href=\"mailto:\\0\">\\0</a>':'\\0'))" ), $text ); }
<?php function auto_link ($text) { return preg_replace('/([^="\'>]|^)(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/', '$1<a href="$2$3" target="_blank">$2$3</a>', $text); } $example = '例文:http://www.yahoo.com/が入力されたら<a href="http://www.yahoo.com/">http://www.yahoo.com/</a>にする。'; echo auto_link ($example); ?>
既にリンクになっているものは無視して、タグのついていないURIのみをリンクに変換します。
時間がないのです、参考にしている。