文字列内のリンクを検出するために preg_replace を試みています。以下の例
$descriptionlink = "This is a test www.google.com";
$descriptionlink = preg_replace('/.*?\b((?:(?:https?|ftp|file):\/\/|www\.|ftp\.)?[-A-Z0-9+&@#\/%=~_|$?!:,.]*[A-Z0-9+&@#\/%=~_|$]\.[-A-Z0-9+&@#\/%=~_|$?!:,.]*[A-Z0-9+&@#\/%=~_|$]).*?/i', '$1', $descriptionlink);
文字列にリンクがあり、希望どおりにリンクのみをエコーアウトすると、うまく機能します。文字列が単なるテキストの場合、テキストがエコーアウトされます。リンクがない場合、文字列内のテキストを見たくありません。
私が望む出力の例
input - This is a test www.google.com
output - www.google.com
上記はうまく機能しますが、これを行い、リンクがない場合は下のテキストをエコーアウトします
input - This is a test
output - This is a test
テキストだけの場合、出力を空白にしたい。
ありがとう