Home >Backend Development >PHP Tutorial >PHP simple thief program
Thief program: Catch the data (pictures, web pages and other files) on the remote website to the local, and then display it after processing
Regular expressions: Used for pattern segmentation, matching, and search of strings and replacement operations.
Related functions:
int ereg(string $pattern
, string $string
[, array &$regs
]
)
If the parameter is omitted and the returned array is found, the return value is True otherwise it returns False
Correspondingly, eregi() is not case-sensitive.
string file_get_contents(string $filename
[, bool $use_include_path
=
false[,resource $context
[,int $offset
=
0[,int $maxlen
]]]]
)
Read the entire file, such as:
Use this function to obtain web page information
It is the basis of the thief program.
For example:
$url=file_get_contents("http://www.ubuntu.org.cn/index_kylin");
echo $url;
?>
But for another website:
$url=file_get_contents("http://www.alangzhong.com/index.html");
echo $url;
?>
I found that many background images are invisible.
Looking at the source code of the web page, we found that this is
src="/upload/201503/b123ec26-bb8f-43be-b5ad-cdf45153d053. png"/>
The address of the image uses a relative path, and we do not have such a file locally, so of course it cannot be displayed.
Use a regular expression to select the image, and then replace the relative path with the remote address:
The timeout problem of the following code has not been resolved.
<?php //ini_set('max_execution_time', '0'); //三者都没用啊,一直超时 //@ini_set('default_socket_timeout', 20000); //set_time_limit(2); $url=file_get_contents("http://www.alangzhong.com/index.html"); //echo $url; $fp = @fopen($url, "r") or die("超时"); //为什么不断超时 $contents = file_get_contents($url); eregi("<img width=\"116\" height=\"98\" src=\"/upload/201503/b123ec26-bb8f-43be-b5ad-cdf45153d053.png\"/>",$contents,$rg); // 远程地址替换相对路径 $rg[1]=str_replace("src=\"../upload/","src=\"http://www.alangzhong.com/index.html/upload/",$rg[1]); echo $rg[1]; ?>
The above introduces the simple thief program in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.