通过.com查找从字符串中删除Url


Remove Url from String by finding by .com

可能重复:
从混合字符串中提取所有URL(php)

我需要一种从var中删除url字符串的方法,但不是找到.然后删除它。不,我需要找到http然后找到.com.net.info,然后删除整个链接

这是我以前的代码

    function cleaner($url) {
  $U = explode(' ',$url);
  $W =array();
  foreach ($U as $k => $u) {
    if (stristr($u,'http') || (count(explode('.',$u)) > 1)) {
      unset($U[$k]);
      return cleaner( implode(' ',$U));
    }
  }
  return implode(' ',$U);
}
$url = "$first";

但那一次删除了。非.com

您可以使用preg_match方法来捕获http和.com之间的内容

preg_match('%^((https?://)|(www'.))([a-z0-9-].?)+(:[0-9]+)?(/.*)?$%i', $url); 

我认为实现这一点但并非没有错误的最简单方法是:

$url="http://codepad.org/";
$arry=explode(".",$url);
$arry1= explode("//",$arry[0]);
echo $arry1[1];