using this pattern
preg_match_all("|http[://]+[A-Za-z0-9_.-]+|", $contents , $matches);
for string
http://some-domain-name.com
gives the result http://some-domain-name.com
however, if I include a slash, whether by itself or escaped
preg_match_all("|http[://]+[A-Za-z0-9_.-/]+|", $contents , $matches);
or
preg_match_all("|http[://]+[A-Za-z0-9_.-\/]+|", $contents , $matches);
I get the result
http://some
How do I include slashes?
including slash inside group
Moderator: General Moderators
-
jaymoore_299
- Forum Contributor
- Posts: 128
- Joined: Wed May 11, 2005 6:40 pm
- Contact:
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
your regex is still going to match lots of incorrect data. Here's a push in the right direction
I can recommend you download and use "Regex Coach"
Code: Select all
preg_match_all('`https?://[A-z0-9_-][A-z0-9_\./-]+`',$text,$matches);