Reputation: 1520
I have a string like:
#05#, #45#, #785#
...etc
I need to remove the hash symbols from either side of each id value so that #01544#
becomes 01544
.
Upvotes: 1
Views: 109
Reputation: 48795
Use this:
preg_replace('(#([0-9]+)#)', '\1', '#05#, #45#, #785#');
Upvotes: 2
Reputation: 91792
You can just use str_replace
:
$id = str_replace("#", "", $your_variable);
Upvotes: 2
Reputation: 76985
Why not just use str_replace
? E.g.
$string = str_replace('#', '', $string);
For simple patterns like this, regex is never necessary.
Upvotes: 2
Reputation: 26360
echo str_replace("#", "", "#05#, #45#, #785#");
more info at:
http://php.net/manual/en/function.str-replace.php
Upvotes: 6