aarongoos Posted November 24, 2006 Share Posted November 24, 2006 Is there any way to do this? If you want to extract the URLs for all the pictures on a given page, it would be easy to match "http://" and ".jpg" and extract anything in between those two strings. I haven't been able to find a function that can extract an unknown length between two elements. Does it exist? Link to comment https://forums.phpfreaks.com/topic/28367-how-to-extract-a-string-between-http-and-jpg/ Share on other sites More sharing options...
fert Posted November 24, 2006 Share Posted November 24, 2006 preg_match() Link to comment https://forums.phpfreaks.com/topic/28367-how-to-extract-a-string-between-http-and-jpg/#findComment-129744 Share on other sites More sharing options...
printf Posted November 24, 2006 Share Posted November 24, 2006 Something like this may work...[code]<?php // the data container that holds the HTML document // you want to extract image URL(s) from... $in = ''; $out = array (); preg_match_all ( "|src\=\"?'?`?([[:alnum:]:?=&@/._-]+)\"?'?`?|i", $in, $src ); for ( $x = 0; $x < sizeof ( $src[1] ); $x++ ) { // we don't want copies on the same image url if ( ! in_array ( $src[1][$x], $out ) ) { $out[] = $src[1][$x]; } } print_r ( $out );?>[/code]printf Link to comment https://forums.phpfreaks.com/topic/28367-how-to-extract-a-string-between-http-and-jpg/#findComment-129782 Share on other sites More sharing options...
Nicklas Posted November 24, 2006 Share Posted November 24, 2006 [CODE]<?php$string = "blabla...";preg_match_all('~http://[^\s]+\.jpg~is', $string, $matches);$matches = array_unique($matches[0]); // remove duplicate values...print_r($matches);?>[/CODE] Link to comment https://forums.phpfreaks.com/topic/28367-how-to-extract-a-string-between-http-and-jpg/#findComment-129795 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.