我如何打开一些这样的链接
http://someaddr.ess/linked [URL NAME]
进入
<a href="http://someaddr.ess/linked">URL NAME</a>
我正在寻找 PHP 或 jQuery 的解决方案。
*我在 stackoverflow 中没有找到专门针对此问题的解决方案。如果您已经知道一些答案,请链接到它。
我如何打开一些这样的链接
http://someaddr.ess/linked [URL NAME]
进入
<a href="http://someaddr.ess/linked">URL NAME</a>
我正在寻找 PHP 或 jQuery 的解决方案。
*我在 stackoverflow 中没有找到专门针对此问题的解决方案。如果您已经知道一些答案,请链接到它。
试试这个代码:
$a = 'http://someaddr.ess/linked [URL NAME]';
echo preg_replace('~(https?://\S+)\s*\[([^\]]+)\]~', '<a href="$1">$2</a>', $a);
//=> <a href="http://someaddr.ess/linked">URL NAME</a>
你可以试试这个,
<?php
$input ="http://someaddr.ess/linked [URL NAME]";
$input =str_replace("]", "", $input);
list($url, $URLTEXT) =explode("[", $input);
$URL = preg_replace('!(http|ftp|scp)(s)?:\/\/[a-zA-Z0-9.?&_/]+!', "<a href=\"\\0\">".$URLTEXT."</a>",$url);
echo $URL;
?>
试试喜欢
$str = "http://someaddr.ess/linked [URL NAME]";
$new_arr = explode(' ',$str);
preg_match_all('/\[([A-Za-z]+?)\]/', $str, $text);
echo "<a href='".$new_arr[0]."'>".$text[0]."</a>";