3007 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+7 more
duotive says
Hello. I was wondering if someone know how to get the urls from a string, like the one below, with php.
http://www.example.com/images/image1.jpg
http://www.example.com/images/image2.jpg
http://www.example.com/images/image3.jpg
http://example.com/images/image4.jpg
/images/image2.jpg
with all the variations described above. That solution eludes me :( Thanks for you help. :D
1383 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
wpCanyonThemes says
3007 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+7 more
duotive says

http://php.net/manual/en/function.parse-url.php

this parses a given url into components. i need to get image urls form a list of urls form users inputs.

3467 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark Moderator says

Can’t you just use the explode() function?

$urls = explode("\n", $url_str);
122 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 10+ items on Envato Market
  • Member of the Envato Team
  • Sells items exclusively on Envato Market
+1 more
ian Envato team says

Use a regular expression:

((?: ([\w+.:-]+:)// | www\. )[^\s<]+)
3007 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+7 more
duotive says

Use a regular expression:
((?: ([\w+.:-]+:)// | www\. )[^\s<]+)

I am using

preg_match_all('((?: ([\w+.:-]+:)// | www\. )[^\s<]+)',$string,$matches);
and its not returning anything. Did i do something wrong?

3007 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+7 more
duotive says

Can’t you just use the explode() function?
$urls = explode("\n", $url_str);

=)))) too simple to work but it did =)))) if anyone knows a regular than can do this it will be amazing, but in the time being this is very good. THANKS !!

2070 posts
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Provided great feedback to improve the user experience on Envato Market
  • Interviewed on an Envato blog
+9 more
revaxarts says


Use a regular expression:
((?: ([\w+.:-]+:)// | www\. )[^\s<]+)
I am using
preg_match_all('((?: ([\w+.:-]+:)// | www\. )[^\s<]+)',$string,$matches);
and its not returning anything. Did i do something wrong?
You forgot some delimiters:
preg_match_all('#((?: ([\w+.:-]+:)// | www\. )[^\s<]+)#',$string,$matches);
3007 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+7 more
duotive says



Use a regular expression:
((?: ([\w+.:-]+:)// | www\. )[^\s<]+)
I am using
preg_match_all('((?: ([\w+.:-]+:)// | www\. )[^\s<]+)',$string,$matches);
and its not returning anything. Did i do something wrong?
You forgot some delimiters:
preg_match_all('#((?: ([\w+.:-]+:)// | www\. )[^\s<]+)#',$string,$matches);
Thanks but still no go. Here is what i have:
            $string = 'http://www.example.com/images/image1.jpg
            http://www.example.com/images/image2.jpg
            http://www.example.com/images/image3.jpg
            http://example.com/images/image4.jpg
            /images/image2.jpg'; 
            $urls = explode("\n", $string);
            print_r($urls);    
            echo '<br /><br />';
            preg_match_all('#((?: ([\w+.:-]+:)// | www\. )[^\s<]+)#',$string,$matches);
            print_r($matches); 
This is just for testing… so, the first one echoes
Array ( [0] => http://www.example.com/images/image1.jpg [1] => http://www.example.com/images/image2.jpg [2] => http://www.example.com/images/image3.jpg [3] => http://example.com/images/image4.jpg [4] => /images/image2.jpg ) 
but the second one
Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) )
2070 posts
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Provided great feedback to improve the user experience on Envato Market
  • Interviewed on an Envato blog
+9 more
revaxarts says

I didn’t test ian’s regex.

if you always have linebreaks at the end than explode is a good solution

EDIT :

https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?
should work for urls (including the protocol)
by
by
by
by
by
by