Get a URL from a String

后端 未结 2 1552
暖寄归人
暖寄归人 2020-12-09 23:40

For a little while now I\'ve been searching for a code to get URL\'s out of a string using PHP. I\'m basically trying to get a Shortened URL out of a message, and then later

2条回答
  •  渐次进展
    2020-12-10 00:04

    Something like:

    $matches = array();
    preg_match_all('/http:\/\/[a-zA-Z0-9.-]+\/[a-zA-Z0-9.-]+/', $text, $matches);
    print_r($matches);
    

    You'll need to tune the regexp to get exactly what you want.

    To get the URL out, consider something as simple as:

    curl -I http://url.com/path | grep Location: | awk '{print $2}'

提交回复
热议问题