3007 posts
  • 5 Years of Membership
  • Affiliate Level 5
  • Author Level 9
  • Bundle Boss
+8 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
  • 5 Years of Membership
  • Affiliate Level 2
  • Collector Level 2
  • Exclusive Author
+1 more
wpCanyonThemes
says
3007 posts
  • 5 Years of Membership
  • Affiliate Level 5
  • Author Level 9
  • Bundle Boss
+8 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.

3535 posts
  • Power Elite Author
  • Author Level 12
  • Trendsetter
  • United States
+13 more
sevenspark
Moderator
says

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

$urls = explode("\n", $url_str);
122 posts
  • 8 Years of Membership
  • Collector Level 2
  • Envato Team
  • Exclusive Author
+1 more
ian
Envato team
says

Use a regular expression:

((?: ([\w+.:-]+:)// | www\. )[^\s<]+)
3007 posts
  • 5 Years of Membership
  • Affiliate Level 5
  • Author Level 9
  • Bundle Boss
+8 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
  • 5 Years of Membership
  • Affiliate Level 5
  • Author Level 9
  • Bundle Boss
+8 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 !!

2280 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Community Superstar
  • Industrious API Inventor
+15 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
  • 5 Years of Membership
  • Affiliate Level 5
  • Author Level 9
  • Bundle Boss
+8 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 ( ) )
2280 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Community Superstar
  • Industrious API Inventor
+15 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