0

我有一个用 PHP 编写的渲染页面,输出以下代码:

    <html>
    <body>
   random code 

    <u>Hello everyone</u>

   random code    
    </body>
    </html>

现在我需要检查页面是否包含字符串“大家好”以及找到时是否包含某些内容,或者在未找到时不执行任何操作。呈现的页面位于同一服务器中。谢谢。

4

3 回答 3

1

试试这个,使用 jQuery

<html>
<head>
</head>
<body>
random code 
<u>Hello everyone</u>
random code 
</body>
</html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
var url="filecont.php"//THE PHP FILE LOCATION
$.post(url, function(data) {
  var count = data.match(/Hello everyone/g); 
  if(count.length<=1){//If its in the same file, because in .match(/Hello everyone/g); already exist
    alert("NOT FOUND");
  }
  else{
    alert("YEAH!, FOUND");
  }
});
</script>
于 2013-05-17T14:03:46.327 回答
1

你也可以试试——

$page_source=file_get_contents("page_url"); //or use curl

if(preg_match("/Hello everyone/i",$page_source)){
    //do something
}
else{
    //do nothing
}
于 2013-05-17T13:47:40.083 回答
0

使用strpos

$isexist = strpos($the_page_text, "Hello everyone");
于 2013-05-17T13:40:17.993 回答