How to remove brackets from string in php?

hairynuggets picture hairynuggets · Jan 23, 2012 · Viewed 50.2k times · Source

I have the following string and would like to use str_replace or preg_replace to remove the brackets but am unsure how. I have been able to remove the opening brackets using str_replace but can't remove the closing brackets.

This is the sting:

$coords = '(51.50972493425563, -0.1323877295303646)';

I have tried:

<?php echo str_replace('(','',$coords); ?>

which removed the opening brackets but am now under the impression that I need preg_replace to remove both.

How does one go about this?

Help appreciated

Answer

hsz picture hsz · Jan 23, 2012

Try with:

str_replace(array( '(', ')' ), '', $coords);