How to obtain JPG images starting with HTTP

Source: Internet
Author: User
How do I obtain JPG images starting with HTTP? When I use & nbsp; simple_html_dom.php, & nbsp;, I only find the image starting with HTTP. how can I add a JPG ending? Foreach & nbsp; ($ html-& gt; find ('IMG [src: How do I obtain JPG images starting with HTTP?
When I use simple_html_dom.php, I only find the image starting with HTTP. how can I add a JPG ending?

foreach ($html->find('img[src^="http"]') as $element) 
 

Or
Which one writes a jpg image preg_match_all starting with HTTP? Thank you. Share To: find ('IMG [src ^ = "h... 'data-pics =''>
------ Solution --------------------
It's not too clear what you want to express. this is what I wrote when I learned regular expressions and obtained a webpage image,

/*
* @ Param string $ url collection url
* @ Param int $ whether isinsite is intra-site. the default value 1 indicates intra-site 0 indicates intra-site out-site
* @ Return string
*/
Function getallimg ($ url, $ isinsite = 1)
{
$ Urlstr = parse_url ($ url );
$ Url = $ urlstr [scheme]? $ Url: "http: //". $ urlstr [path]; // you can specify whether the url you entered contains http: //.
$ Urlstr = parse_url ($ url );
$ Site = "http: //". $ urlstr [host]; // obtain the address of this site
$ Subject = file_get_contents ($ url );
$ Pattern = '/. * ------ solution --------------------
\ "] (. * 2.16.jpg
------ Solution --------------------
. Gif
------ Solution --------------------
. Png]) [\'
------ Solution --------------------
\ "]. * \/?>. */U'; // The // is the separator
Preg_match_all ($ pattern, $ subject, $ result); // you can specify all matched items.
If ($ isinsite = 0)
{
Foreach ($ result as $ key => $ value) // Two-dimensional array $ result [n] [m];
{
If ($ key = 1)
{
Foreach ($ value as $ key => $ value) // Obtain $ result [m]
{
$ Isownsite = parse_url ($ value );
$ Url = $ isownsite [host]? $ Value: $ site. $ isownsite [path]; // Obtain all images of the webpage and
$ Imgcontent. ="
------ Solution --------------------
";
}
}
}
}
If ($ isinsite = 1)
{
Foreach ($ result as $ key => $ value) // Two-dimensional array $ result [n] [m];
{
If ($ key = 1)
{
Foreach ($ value as $ key => $ value) // Obtain $ result [m]
{
$ Isownsite = parse_url ($ value );
$ Url = $ isownsite [host]? NULL: $ site. $ isownsite [path]; // only obtain external URLs not included in the site
If ($ url! = NULL)
$ Imgcontent. ="
------ Solution --------------------
";
}
}
}
}
Return $ imgcontent;
}
?>


Search for intra-site images

Search for out-of-site images across the entire site

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.