Php code to replace brackets in a particular text

 You may be faced with a situation to remove text inside the bracket,wonder how it can be done.. it can be easily done by preg_replace function

Here is the preg_replace function code to replace text inside brackets(along with brackets)by freespace

$text1=preg_replace("/(\([A-Za-z0-9.',()]+)\)/si”,”",$text);

Explanation of the code:

a)First ‘/’ and ‘/’ are delimiters

b)’('  - this stats the replacing text should start with ‘(’

c)After thna grouping starts with ‘(’ and ‘)’

d) ([A-Za-z0-9.',()]+        - This code states tha matching code can contain any number of A-Z,a-z,0-9,. , ‘,’,(,) characters

e)Grouping ends with ‘)’

f)delimiters are followed by ‘i’ and ’s’ which indicates that text is case insensitive

This entry was posted on Tuesday, February 24th, 2009 at 10:05 pm and is filed under Php. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

Post a Comment