Welcome Guest, Not a member yet? Register   Sign In
regular expression help - proprtly pase full url from string
#1

[eluser]new_igniter[/eluser]
Hello,
Can someone share a regex that properly handles grabbing a http link from a string of text?
What I have below works, but not in all circumstances, i.e. link has ),>,:, etc on the end. So I would love to know people's experiences with this and how they solved it.

Thanks!

Code:
$regex = '/(http:\/\/[^&"\'\s]+)/i';
        if (preg_match_all($regex, $text, $matches, PREG_SET_ORDER))
        {
           $link = $matches[0][0];
        }

for CI search: regex grab url from text, grab url from string,
#2

[eluser]Pascal Kriete[/eluser]
Take a look at the auto_link function in the URL Helper, to see how CI handles it (system/helpers/url_helper.php :: line 377).

You might also be interested in the work Sophistry has done here.

Hope that helps.
#3

[eluser]new_igniter[/eluser]
Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB