Php 接受url或字符串的函数?

Php 接受url或字符串的函数?,php,protocols,file-get-contents,Php,Protocols,File Get Contents,我有一个函数,我希望能够接受一个html字符串,或者一个文件内容可以使用的资源 我的基本想法是 function something($source){ $local = true; foreach(array('http://', 'https://') as $protocol) if(stripos($source, $protocol) === 0) $local = false; //more stuff } 这是有效的, 但我很好奇,有没有更好的方法

我有一个函数,我希望能够接受一个html字符串,或者一个文件内容可以使用的资源

我的基本想法是

function something($source){
  $local = true;
  foreach(array('http://', 'https://') as $protocol)
    if(stripos($source, $protocol) === 0)
      $local = false;
  //more stuff
}
这是有效的, 但我很好奇,有没有更好的方法来实现这一点,如果没有,还有什么其他协议可以处理文件内容?这是正常的方法。