Matt M. wrote:

on one place I have string "something (something_2)"
I have to take out of the string everything in brackets and brackets as
well.
probably I will need to use Regular Expression Functions but I'm really
bad with them :)


$string = "something (something_2)";
$pattern = "/\(.*\)/";
$replacement = "";
echo preg_replace($pattern, $replacement, $string);

Just note that if there are two "bracketed" patterns in a string, this will have issues. It may or may not be an issue for you, though, depending up on your data.


As an alternative:

$string = "something (something_2) something (something_4)";
$pattern = '/\([^)]\)/';
//or $pattern = '/\(.*\)/U';
$replacement = '';
echo preg_replace($pattern, $replacement, $string);

Also, if there could be line breaks within the "bracketed" text, you'll need extra modifiers... it all just depends upon your data.

--

---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to