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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.