strip_tags + html实体只获取数字

I would like to remove everything but the amount as a float from this string:

<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#8362;</span>700.00</span>

I tried:

  1. strip_tags( $total_price_paid ); - Not enough.
  2. strip_tags( html_entity_decode( $total_price_paid ) ); - it decodes the entity into a symbol, i tried preg_replace after and it didn't work.
  3. preg_replace( '/[^0-9]/', '', $value ); - Doesn't get rid of html entity

None of those achieved a result of 700.00 formatted as a float.

Can anyone help please?

Thanks!

You need to remove also the special pieces of text used to define entities, so you need at least another pass:

$total_price_paid = strip_tags($total_price_paid);
$total_price_paid = preg_replace("/&#?[a-z0-9]{2,8};/i", "", $total_price_paid); 

Code snippet is available here.

$str = '<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">₪</span>700.00</span>';

echo floatval(substr($str, stripos($str, "</span>")+7, strripos($str, "</span>")+7));

If you want to use preg_match then you can use like that:

$string = '<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#8362;</span>700.00</span>';

preg_match('/\d+\.\d{1,2}/', $string, $matches);

echo $matches[0]; // 700.00

DEMO