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