A question about the str_replace function

Source: Internet
Author: User
Ask a question about a str_replace function. for example, if the following data set is 00010,00014, 20171000023,24, 0027,0000, I want to remove all the values 0, but ", "0 before" is not removed, that is, 00010,00014, 000000002 ask a question about the str_replace function.
For more information, see the following data set.

00010,00014, 20171000023,24, 0027,0000

I want to remove all the 0 values, but do not remove the 0 values before ",".

That is

00010,00014, 20171000023,24, 0027,0000

This set of data becomes

, 27

What should I do?

------ Solution --------------------
Echo preg_replace ('/(^ |,) 0 +/', '$ 1', '2014, 00010,000, 0000 ');

, 27,

1. str_replace can only replace fixed strings. a regular expression is required for an indefinite string.
2. I don't think the result of, 27 is correct, because he lost
------ Solution --------------------
PHP code
$ Str = "00010,00014, hour, hour 23, 24,0027, 0000"; echo trim (preg_replace ("/[^,] + ,? /E "," intval ('\ 0')> 0? Intval ('\ 0').', ': ''", $ str),', '); //, 27

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.