开发者

PHP preg replace help

开发者 https://www.devze.com 2023-03-03 07:42 出处:网络
HI, I have t开发者_如何学编程hese strings: #05#, #45#, #785# ...etc I need to get the id so #01544# become 01544. How can I do?

HI, I have t开发者_如何学编程hese strings:

#05#, #45#, #785# ...etc

I need to get the id so #01544# become 01544. How can I do?

Thanks!


echo str_replace("#", "", "#05#, #45#, #785#");

more info at:

http://php.net/manual/en/function.str-replace.php


Use this:

preg_replace('(#([0-9]+)#)', '\1', '#05#, #45#, #785#');


Try

$str = trim('#01544#', '#');


Why not just use str_replace? E.g.

$string = str_replace('#', '', $string);

For simple patterns like this, regex is never necessary.


You can just use str_replace:

$id = str_replace("#", "", $your_variable);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号