TexasMd91 Posted August 15, 2008 Share Posted August 15, 2008 I currently have a string like this. <p><span style="font-size:0.8em;">songs played:</span> 152</p> <p><span style="font-size:0.8em;">radio count:</span> 1</p> Now, I need to parse it and find out what is between radio count:</span> and </p> I thought about using the strpos to find where exactly the string is, and then using that to grab the data inbetween. However, it would find the </p> after the 152 instead of the </p> after the 1. Any suggestions on how to achieve this? Quote Link to comment https://forums.phpfreaks.com/topic/119846-parsing-a-string-between-2-strings/ Share on other sites More sharing options...
adam84 Posted August 15, 2008 Share Posted August 15, 2008 Couldn't you get put all the information you want to access in the 'radio count:' span tag and just used the .innerHTML property to get the text found in the span tag? Quote Link to comment https://forums.phpfreaks.com/topic/119846-parsing-a-string-between-2-strings/#findComment-617412 Share on other sites More sharing options...
JonnoTheDev Posted August 15, 2008 Share Posted August 15, 2008 Will get you the numeric value of the radio count: $string = '<p><span style="font-size:0.8em;">songs played:</span> 152</p><p><span style="font-size:0.8em;">radio count:</span> 1</p>'; $string = strip_tags($string); preg_match('/radio count: ([0-9]+)/', $string, $matches); print $matches[1]; Quote Link to comment https://forums.phpfreaks.com/topic/119846-parsing-a-string-between-2-strings/#findComment-617417 Share on other sites More sharing options...
TexasMd91 Posted August 15, 2008 Author Share Posted August 15, 2008 Couldn't you get put all the information you want to access in the 'radio count:' span tag and just used the .innerHTML property to get the text found in the span tag? The problem is, its not my HTML. I am using file_get_contents on a website to retrieve stats. Thanks neil.johnson, that worked Quote Link to comment https://forums.phpfreaks.com/topic/119846-parsing-a-string-between-2-strings/#findComment-617459 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.