CodeIgniter Forums
preg match help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: preg match help (/showthread.php?tid=9198)



preg match help - El Forum - 06-16-2008

[eluser]new_igniter[/eluser]
Does anyone have a function on hand for parsing text for links that being with http, www, and grabbing the matches?

I have a bunch of links on my page that begin with http://www.tinyurl.com/[what tinyURL creates] and want to grab those links out of a string of text.


preg match help - El Forum - 06-16-2008

[eluser]mglinski[/eluser]
/^http(.*)\s/

Try that, just add http to the beginning of every match.
Might not work, i dont use preg much.
-Matt


preg match help - El Forum - 06-17-2008

[eluser]sophistry[/eluser]
you pretty much wrote the regex yourself!

Code:
http://www.tinyurl.com/([^\s]+)

that means look for the whole tiny url domain with http:// and then capture anything that is not a space character. this won't work if the urls are in hrefs (as in the urls are in HTML code rather than straight txt) because typically the href uses double quotes to delimit the end of the url. in that case you should be able to just replace the \s with ".

with that in preg_match function you'll have the tinyurl string in array item 1.

let us know.

cheers.