Jump to content

a little help please!


daydreamer

Recommended Posts

I am trying to get a number from a string that will be in the range of 0.00 to 99.99.

 

It will occur in the string like this:

 

   <p><em class="example">
			                     3.30
							</em></p>

 

spaces included!

 

here is what i have so far:

 

<?php
preg_match("/(?=\"example\"> \s)[0-9]\.[0-9][0-9]+/",$xxx,$matches);
print_r($matches);
?>

 

What do i need to change?

 

thanks.

Link to comment
https://forums.phpfreaks.com/topic/125809-a-little-help-please/
Share on other sites

Perhaps I'm splitting hairs here (I get the sense I am).. but I noticed the dot is not escaped in the pattern (thus it will capture any single character between the set of digits). depending on the data found in <em class="example">, the current pattern could find '3-30' for example. If there is a possibility to have something other than the dot between digits, would you not need to escape it in the pattern?

 

preg_match('/<em class="example">\s*(\d{1,2}\.\d{2})/', $data, $matches);

 

But again, depending on how the data that is found in <em class="example"> is decided / filtered, it probably doesn't matter?

Link to comment
https://forums.phpfreaks.com/topic/125809-a-little-help-please/#findComment-652391
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.