Search code examples
phpreplacestring-literalssanitization

Remove all hash symbols in a string


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.


Solution

  • Use this:

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