Home > Backend Development > PHP Tutorial > 新手请问个PHP查找TXT内容并输出的有关问题

新手请问个PHP查找TXT内容并输出的有关问题

WBOY
Release: 2016-06-13 10:08:51
Original
912 people have browsed it

新手请教个PHP查找TXT内容并输出的问题!
新手请教个PHP查找TXT内容并输出的问题!

1.TXT里的内容如下:

HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->101010100=北京101010200=海淀101010300=朝阳101010400=顺义101010500=怀柔101010600=通州101010700=昌平101010800=延庆101010900=丰台101011000=石景山101011100=大兴101011200=房山101011300=密云101011400=门头沟101011500=平谷101011600=八达岭
Copy after login


我想通过PHP来实现查询
比如http://127.0.0.1/1.php?city=北京 就能找到对应的101010100
不会PHP 只好来求助,麻烦大虾给段详细的代码!

------解决方案--------------------

//随便写了下,注意data.txt为gb2312编码
PHP code
$city=$_REQUEST["city"];$city=iconv("utf-8","gb2312",$city);if ($city){    $fp=fopen("data.txt","r");    while (!feof($fp))    {        $buffer = fgets($fp);        list($code,$area)=explode("=",$buffer);        if (trim($area)==$city)        {            echo $code;        }    }    fclose($fp);}?><br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨

引用:
echo urldecode("%E5%8C%97%E4%BA%AC");
输出 :北京

记得txt文件与你的php文件编码要统一,否则会乱码,或者要转化一下也可。


谢谢解答,我现在碰到的问题是
我直接用2楼的那个代码,没有任何输出,原因是查询时 汉字没有urlencode

我不知道怎么加,PHP完全不懂!
我……
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template