[英]Search for a string in HTML source rendered page with PHP
我有一個用PHP編寫的呈現頁面,它輸出以下代碼:
<html>
<body>
random code
<u>Hello everyone</u>
random code
</body>
</html>
現在,我需要檢查頁面是否包含字符串“大家好”,並且在找到時顯示內容,或者在未找到時不執行任何操作。 呈現的頁面位於同一服務器上。 謝謝。
使用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>
使用strpos
$isexist = strpos($the_page_text, "Hello everyone");
您也可以嘗試-
$page_source=file_get_contents("page_url"); //or use curl
if(preg_match("/Hello everyone/i",$page_source)){
//do something
}
else{
//do nothing
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.