Jump to content

Remove all alpha characters from a string


illuz1on

Recommended Posts

Hi,

 

Im looking at using a statement like this to remove all text characters from a string.

 

  $outgoing = substr_replace($incoming,"",-1); 

 

The string is a currency that has a currency symbol in the beginning of the string, like "R500.00"

 

I would like to remove the R, so it is just a numeric value...

 

Please can you help me with any ideas on how to get this going? Been reading so much and its all confused me too badly.

 

Regards,

Chris

I have made a bit more progress...

 

<?php

$mynewprice = $product_price;

 

function deleteFirstChar( $mynewprice ) {

return substr( $mynewprice, 1 );

}

$rightprice = deleteFirstChar( $mynewprice );

?>

 

I was hoping $rightprice would be the stripped value of 550.00

 

--------------------------

 

I think im struggling because $product_price returns this:

 

<div class="yagendoo_productPrice">

<span class="yagendoo_productPrice"> R550.00 </span>

</div>

 

So I think now, I need to make it strip ALL characters except for numeric chars..

 

Any ideas?

would this help you?

$string = '100.000.000 zilion trillion billion euros';
            $pattern = '/[^0-9]/i';
            $replacement = '';
            echo preg_replace($pattern, $replacement, $string); // this will output 100000000

 

Put your code in code tags btw  ::) much easier to read it

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.