<?php
$url = "savings.gov.pk/wp-content/uploads/2017/03/15-11-201120Rs.1500.txt";
if (strpos($url, "505153")!==false){
echo "Number Here";
}
else {
echo "No Number Here :(";
}
?>
我在此网址中找到了奖金保证金的数量 http://savings.gov.pk/wp-content/uploads/2017/03/15-11-201120Rs.1500.txt
但是我失败了,我不知道代码如何使用php查找数字
我找到的号码是'505153'
答案 0 :(得分:1)
您的代码是否在URL中检查“ 505153”,我认为您需要在txt文件中检查“ 505153”。你可以试试这个
$content = trim(file_get_contents('http://savings.gov.pk/wp-content/uploads/2017/03/15-11-201120Rs.1500.txt'));
if ($content) {
if (strpos($content, "505153") !== false) {
echo "Number Here";
} else {
echo "No Number Here :(";
}
} else {
echo "No Content found";
}
答案 1 :(得分:1)
您需要使用php curl 或 file_get_contents()从指定的url中获取债券数据,然后才能在数据中找到您的号码。 当我尝试下面的代码时,我收到 Number Here 消息。希望有帮助
$url =
file_get_contents("http://savings.gov.pk/wp-
content/uploads/2017/03/15-11-
201120Rs.1500.txt");
//then try to find your number on the text
if (strpos($url, "505153")!==false){
echo "Number Here";
}
else {
echo "No Number Here :(";
}
参考
卷曲: http://php.net/manual/en/book.curl.php
file_get_contents: http://php.net/manual/en/function.file-get-contents.php