Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/119846-parsing-a-string-between-2-strings/
Share on other sites

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];

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 :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.