Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
これにより、ターゲットが追加されます。
$string = preg_replace("/<a(.*?)>/", "<a$1 target=\"_blank\">", $string);
これは、URL を検出してリンクにする大雑把な方法です (これは脆弱です)。
$string = preg_replace("/(http[^\ ]+)/", "<a href=\"$1\" target=\"_blank\">$1</a>", $string);
まず、XML/HTML 処理ライブラリを使用してタグ間のテキストを取得し、次に単純な正規表現を使用します。
URL の PHP 検証/正規表現
すべての URL をリンクとして作成します。