Search code examples
phpstringpreg-replacestr-replace

How to remove brackets from string in php?


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


Solution

  • Try with:

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