Jump to content

preg_replace remove ,0 or ,1 also remove first zero


CBG

Recommended Posts

First problem fixed.

My second problem is if the result is 0X.XX,0 or 0X.XX,1 I would like to remove the first 0

The X.XX are numbers, but the 0 is not always there.

 

Can anyone help please

Thanks

Link to comment
Share on other sites

I have the first problem fixed.

With it removing ,0 or ,1 by using

 

$str2 = $newstring;
$pattern2 = "{\,1||,0+}";
$newstring2 = preg_replace($pattern2,"",$str2);
echo '<br>';
echo $newstring2;

 

Now it just leaves removing the first 0 if it exists

Link to comment
Share on other sites

Thanks for the reply.

 

This is working to well

$str = '0x.xx';
echo ltrim($str,'0');

 

Let say it is 00.00 I am wanting to remove the first 0

Then again it could be 01.00 I want to remove the first 0

Or it could be 10.00 which mean there is no 0 to remove

 

The numbers could be anything.

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.