CSkovholm Posted October 19, 2010 Share Posted October 19, 2010 Hey experts. I'm using file_get_contents to save a html page into a variable called $djdanmark. Inside that html page i have a line, like this: <font class="class_1">Some Text</font> Now what i want do to by regex, is to retrieve the text inside those two tags. But as far as i am concerned, you can't use the " inside a variable in php.. My code looks like this: $pattern = "/<font class="class_1">(.*?)<\/font>/"; preg_match($pattern, $djdanmark, $matches); echo $matches[1]; Can someone help me with this? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted October 19, 2010 Share Posted October 19, 2010 $pattern = '~<font class="class_1">([^<]+)</font>~'; Quote Link to comment Share on other sites More sharing options...
CSkovholm Posted October 19, 2010 Author Share Posted October 19, 2010 Thanks!! Quote Link to comment Share on other sites More sharing options...
salathe Posted October 19, 2010 Share Posted October 19, 2010 In case Jay's answer wasn't clear, or you didn't think to wonder why it works, please take a read of the strings documentation for info about the different styles. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted October 19, 2010 Share Posted October 19, 2010 But as far as i am concerned, you can't use the " inside a variable in php Where on Earth did you get that crazy idea? 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.