在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
<?php /** * 文本路径转换为有链接的文字 * @param string $str 转换内容 * @return string */ function urlToLink($str) { $arr = array("www." => "http://www."); $str = strtr($str, $arr); $arr = array("http://http://" => "http://"); $str = strtr($str, $arr); $str2 = explode("http://", $str); for ($n = 1; isset($str2[$n]); $n ++) { $str3 = explode(".", $str2[$n]); if (isset($str3[1])) { $str4 = explode("www.", $str2[$n]); if ((isset($str4[1]) && isset($str3[2])) || !isset($str4[1])) { $length = strlen($str2[$n]); for ($i = 0; $i <= $length; $i ++) { //从空格断开 if (($i - 1) == strlen(trim(mb_substr($str2[$n], 0, $i, 'gb2312')))) { $ii = $i - 1; $url1 = mb_substr($str2[$n], 0, $ii, 'gb2312'); $url2 = mb_substr($str2[$n], $ii, $length, 'gb2312'); $url3 = "<a href=\"http://" . $url1 . "\" target=\"_blank\">http://" . $url1 . "</a>" . $url2; break; } //从出现汉字处断开 if ($i != strlen(mb_substr($str2[$n], 0, $i, 'gb2312'))) { $ii = $i - 1; $url1 = mb_substr($str2[$n], 0, $ii, 'gb2312'); $url2 = mb_substr($str2[$n], $ii, $length, 'gb2312'); $url3 = "<a href=\"http://" . $url1 . "\" target=\"_blank\">http://" . $url1 . "</a>" . $url2; break; } if ($i == $length) $url3 = "<a href=\"http://" . $str2[$n] . "\" target=\"_blank\">http://" . $str2[$n] . "</a>"; } } else $url3 = "http://" . $str2[$n]; } else $url3 = "http://" . $str2[$n]; $url .= $url3; } if (substr($str, 0, 7) == "http://") $url = "<a href=\"http://$str2[0]\" target=\"_blank\">" . $str2[0] . "</a>" . $url; else $url = $str2[0] . $url; return $url; } ?>
|
2022-08-18
2022-07-29
2022-08-17
2022-09-18
2022-08-17
请发表评论