php pattern matching?

  • Thread starter Thread starter GregMason
  • Start date Start date
G

GregMason

Guest
In php I have a string "something (more)" and I want to replace the (....) whatever is in the brackets including the brakets. How can I do this?
 
The code snippet below should replace the parentheses and whatever's inside them with the contents of the $replacement variable, unless I screwed up the regex. Check the php manual entry for preg_replace for a more detailed discussion of this function.

<?php

$string = 'something (more)';
$replacement = 'less';
$string = preg_replace('/\(*.\)/',$replacement,$string);

echo $string;

?>
 
Back
Top