PHP获取源代码并搜索Word

0 php regex search

我需要帮助,我想编写一个程序来搜索源代码中的单词.

这是Python中的一个例子:

import urllib2, re

site = "http://stackoverflow.com/"
tosearch = "Questions"
source = urllib2.urlopen(site).read()
if re.search(tosearch,source):
     print "Found The Word", tosearch
Run Code Online (Sandbox Code Playgroud)

Jul*_*eff 7

<?php

$site = "http://stackoverflow.com/";
$tosearch = "Questions";
$source = file_get_contents($site);
if(preg_match("/{$tosearch}/", $source)): // fixed, thanks meouw
  echo "Found the the word {$tosearch}";
endif;

?>
Run Code Online (Sandbox Code Playgroud)