检查 URL 是否包含某些字符串

Check if URL contains certain strings

如何检查 url ($u) 中是否包含 embed-.html

我有这个:

function embed($u){
$servidores = array('http://powvideo.net/', 'http://gamovideo.com/', 'http://vidspot.net/');
$embedurl = array('http://powvideo.net/embed-', 'http://gamovideo.com/embed-', 'http://vidspot.net/embed-');
    $a = str_replace($servidores, $embedurl, $u);
return $a.'.html';
}

从url中提取路径,并检查它是否以'/embed':

开头
function embed($u){
  $path = parse_url($u, PHP_URL_PATH);
  if(strpos($path, '/embed-') === 0) {
      return $u;
  }
  $servidores = array('http://powvideo.net/', 'http://gamovideo.com/', 'http://vidspot.net/');
  $embedurl = array('http://powvideo.net/embed-', 'http://gamovideo.com/embed-', 'http://vidspot.net/embed-');
  $a = str_replace($servidores, $embedurl, $u);
  return $a.'.html';
}

echo embed('http://powvideo.net/embed-n790e6gzhmmp-960x450.html') . "\n";

echo embed('http://powvideo.net/n790e6gzhmmp-960x450') . "\n";