skitchen Posted November 17, 2008 Share Posted November 17, 2008 Hi there I've been trying to figure out a way of doing this using various options but with little success. I have the html output of a full webpage and I have no control over how the webpage is output and I am using the file_get_contents() function to retrieve it. I only need to extract two pieces of information from the results page. This is the the section of the code with the information that I need to "extract" in bold. <em> Your reference number is [b]XYZ321[/b].</em> </h2> <p class="subtitle"><em> Your voucher is valid until [b]30 September 2009[/b].</em></p> Can anybody provide any help as to how to retrieve just the reference number and the expiry date? Thanks very much Steve Quote Link to comment https://forums.phpfreaks.com/topic/133074-extract-certain-values-from-html-code/ Share on other sites More sharing options...
The Little Guy Posted November 17, 2008 Share Posted November 17, 2008 You could try this (there may be a better way): $input = '<em> Your reference number is XYZ321.</em> </h2> <p class="subtitle"><em> Your voucher is valid until 30 September 2009.</em></p>'; if(preg_match("~is (.+?).~",$input,$matches)){ print_r($matches); }else{ echo 'no matches'; } if(preg_match("~until (.+?).~",$input,$matches)){ print_r($matches); }else{ echo 'no matches'; } Quote Link to comment https://forums.phpfreaks.com/topic/133074-extract-certain-values-from-html-code/#findComment-692041 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.