Trim between characters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Trim between characters

Post by GeXus »

Hello,

If I had the following string: Good Movie (Widescreen)

and I wanted to delete the (Widescreen), so everything inbetween the parren and including the parren.

How would I do this??

Thank you!
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

$str = 'Good Movie (Widescreen)';
$newstr = preg_replace("#\(.*?\)#",$str);
echo $newstr;
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

scottayy wrote:

Code: Select all

$str = 'Good Movie (Widescreen)';
$newstr = preg_replace("#\(.*?\)#",$str);
echo $newstr;
Thanks! But I receive an error "Wrong parameter count"
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

Missing one parameters :

Code: Select all

<?php
$str = 'Good Movie (Widescreen)';
$newstr = preg_replace("#\(.*?\)#", "", $str);
echo $newstr;
?>
Post Reply