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