网址中的搜索号码

时间:2018-08-16 00:48:50

标签: php html

<?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'

2 个答案:

答案 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