English 中文(简体)
PHP图像链接筛查
原标题:Screen Scraping of Image Links in PHP

我有一个网站,包含许多不同的产品页,每一页都有相同格式的图像。 我希望能够检查每一页的ur,以便我能够从每一页中检索每个图像的ur。 想法是为每一页打包,由热链接图像组成。

我知道,这项工作可以在营地进行,但我并不肯定如何拆除多链接的网页。 任何想法?

最佳回答
问题回答

你们可以经常使用一种表达方式,穿过页面来源,并穿透所有环流体。

这一格格外工作:<img[^>]+src=”(*?)

这项工作如何?

// <img[^>]+src="(.*?)"
// 
// Match the characters "<img" literally «<img»
// Match any character that is not a ">" «[^>]+»
//    Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
// Match the characters "src="" literally «src="»
// Match the regular expression below and capture its match into backreference number 1 «(.*?)»
//    Match any single character that is not a line break character «.*?»
//       Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
// Match the character """ literally «"»

Sample PHP代码:

preg_match_all( /<img[^>]+src="(.*?)"/i , $subject, $result, PREG_PATTERN_ORDER);
for ($i = 0; $i < count($result[0]); $i++) {
    // image URL is in $result[0][$i];
}

你们必须做一点更多的工作,解决像相对的URLs这样的问题。

我确实喜欢。 PHP Private RUS DOM Parser for matters such as this. gra光图像的例子在前页是正确的:

// Create DOM from URL or file
$html = file_get_html( http://www.google.com/ );

// Find all images
foreach($html->find( img ) as $element)
       echo $element->src .  <br> ;




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...