Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 845
hairynuggets Avatar asked Jan 23 '12 13:01

hairynuggets


1 Answers

Try with:

str_replace(array( '(', ')' ), '', $coords);
like image 98
hsz Avatar answered Oct 11 '22 16:10

hsz