In my case it will be actually "product name (product number)" and always the same. That means Matt's code will do exactly what I need.
But, thanks for your post - could happen to use that on other place
:)


Thanks John

-afan


John Holmes wrote:
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.


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



Reply via email to