hno Posted July 11, 2010 Share Posted July 11, 2010 Hi every one I have a variable like $a that it has this value ==> $a="<a href="http://www.exam.com" id="id1" >"; and I want to retrieve the data between these two characters , " " In this example it should retrieve www.exam.com . How can I do so ? thanks Quote Link to comment Share on other sites More sharing options...
joel24 Posted July 11, 2010 Share Posted July 11, 2010 use pregmatch http://php.net/manual/en/function.preg-match.php preg_match('/"([^"]+)"/', $a, $url); or you could use the substr() function http://php.net/manual/en/function.substr.php play around with some string functions. Quote Link to comment Share on other sites More sharing options...
leewad Posted July 11, 2010 Share Posted July 11, 2010 The following code will do it: $start_limiter = 'http'; $end_limiter = '.com'; $a='<a href="http://www.exam.com" id="id1" >'; # Step 1. Find the start limiter's position $start_pos = strpos($a,$start_limiter); # Step 2. Find the ending limiters position, relative to the start position $end_pos = strpos($a,$end_limiter,$start_pos); // display http://www.exam.com $url = substr($a, $start_pos, ($end_pos+4)-$start_pos); // display www.exam.com $url2 = substr($a, $start_pos+7, ($end_pos-3)-$start_pos); echo $url."<BR>".$url2; Quote Link to comment 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.