greenheart Posted October 7, 2009 Share Posted October 7, 2009 Hello I am using preg_match to find a http address in a string. Here is my code: preg_match_all("#href=\"(http://[^']+)\"#", $string, $matches); print_r($matches); Problem is it gives e.g http://www.example.com/review"> followed by images (which are in img tags next to the address in the string) when I want http://www.example.com/review without the ">. I tried to specify it ends in " but it goes on past the " and onto the next ". Please help me, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/176875-preg_match-http-problem/ Share on other sites More sharing options...
cags Posted October 7, 2009 Share Posted October 7, 2009 You start your href with a double quote and say anything but single quote repeat. Without really looking at the main logic of the regex I would have thought it should be more along the lines of... '#href="(http://[^"]+)#' Quote Link to comment https://forums.phpfreaks.com/topic/176875-preg_match-http-problem/#findComment-932635 Share on other sites More sharing options...
greenheart Posted October 7, 2009 Author Share Posted October 7, 2009 That works perfectly. I'll have to look at that carefully. Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/176875-preg_match-http-problem/#findComment-932641 Share on other sites More sharing options...
cags Posted October 7, 2009 Share Posted October 7, 2009 Basically it says find instances of href="http:// and any other characters untill you encounter another double quote. Quote Link to comment https://forums.phpfreaks.com/topic/176875-preg_match-http-problem/#findComment-932644 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.