0

Ok , I would like to dynamically automatically parse URLS from tweets that update on my application automatically , I tried to parse them using parse_url function in PHP but it doesn't return what I expect .. I'd basically like to only catch the URL from the tweet..

Example : John McCain's most updated tweet says :

Must-read Jackson Diehl: "What the #Iraq war taught me about #Syria" http://t.co/7YHYQY6bW0

After using parse_url to catch the URL from that tweet , it returned this

array(2) { ["path"]=> string(35) "Must-read Jackson Diehl: "What the " ["fragment"]=> string(55) "Iraq war taught me about #Syria" http://t.co/7YHYQY6bW0" }

I'd basically like to only catch http://t.co/7YHYQY6bW0 or any other multiple urls inside the same tweet ... How can i do this in PHP ?

hakre
  • 193,403
  • 52
  • 435
  • 836

1 Answers1

0

parse_url is for splitting off the pieces of a URL itself. You'll want to do something like preg_match_all since there could potentially be more than one URL in a tweet.

<?php
    $string = 'Must-read Jackson Diehl: "What the #Iraq war taught me about #Syria" http://t.co/7YHYQY6bW0';

    preg_match_all('!http[s]?://[^ ]+!',$string,$urls);

    print_r($urls);

?>
AbsoluteƵERØ
  • 7,816
  • 2
  • 24
  • 35