Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remove strings

Status
Not open for further replies.

hunt00

Technical User
Mar 6, 2005
79
0
0
US
I have the string $orig. Could someone help me to remove all the brackets and strings inside the brackets? The result will look like $final.

$orig = "text1<something>text2<others>text3";
$final = "text1text2text3";

Thanks very much!
 
Code:
$pattern = '/<.*?>/i';
$final = preg_replace($pattern, '', $orig);

or, not using regex (and the manual recommends not using regular expressions when there is an alternative)

Code:
$final = strip_tags($orig);
 
Thanks greatly! It works very well!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top