PHP regular expression to write weather forecast thief program_PHP tutorial

WBOY
Release: 2016-07-13 17:46:04
Original
883 people have browsed it

I used to see that the content on other people's websites was automatically updated every day, and I thought this technology was amazing.
I have also been wondering why their website is not big and it is impossible to have their own weather forecast center,
But the weather forecast is automatically updated every day, and I learned from others that it is because there is such a thing as a thief program~
To put it nicely, the thief program is a collection program, which collects information from other people's websites and puts it on your own website.
The principle of the collection program is to use regular expressions to match and replace content read from other websites, and then display it on your own website.
Let’s talk about a weather forecast thief program that I implemented using PHP regular expressions.
Target site: **Weather Forecast Network
Reason: There is not a lot of code, it is easier to find relevant content for interception and positioning
Implementation steps:
①Read the content of Wentian.com web page with string
Use the php function $str=file_get_contents("url"); to read the web content of the target site and assign it to the $str variable
② Use the regular expression function eregi to match the required content
eregi("regular expression","matched string $str","return value");
③Find and replace some content
Use $str2=str_replace("replaced string", "replaced string", "original string");
The purpose of using the string replacement function here is to replace the path of the picture of the weather forecast status so that the picture can be displayed normally
④Output the results to the web page
echo $str2;
ok~ Now a simple thief program is completed.
Below is a screenshot of the final effect:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478607.htmlTechArticleI used to see that the content on other people’s websites was automatically updated every day, and I thought this technology was amazing. I have also been wondering why their website is not big and it is impossible to have their own weather forecast...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!