使用file_get_contents查找并打印特定的url或web地址


find and print specific url or web address using file_get_contents

我有文件website .txt,这个文件有文本没有安排(它是一个源html代码),我想搜索这个源代码,找到匹配example.com/sub/text的url(所以任何以example.com/sub/text开头的url都应该匹配),并打印/echo它们。

我使用file_get_contents,只需要打印匹配http://www.example.com/sub/text/

我尝试preg_match,但我不知道如何创建一个模式从(http://www.example.com/sub/text/)

试试这个:

 $pattern="%http://www.+[a-z]+/+[a-z]+/+[a-z]+/%";
if(preg_match_all($pattern,$content,$match)) {

    print_r($match);

}

pdf -> something like this: $pattern="%http://www.+[a-z]+/+[a-z]+/+[a-z]+.pdf%";

为了理解目的,检查一下,复制并在你那边测试。

$contentss = file_get_contents("http://www.ncbi.nlm.nih.gov/pubmed?LinkName=pubmed_pubmed&from_uid=18032633" );
preg_match('/<div class="rprt">(.*)<'/div>/',$contentss,$matches);  
echo $matches[0];