Reputation: 10838
In PHP, how to remove string between Active/End Date parenthesis?
For example:
$String1 = "Text Text - (Active Date: 12-03-2011 , End Date:12-03-2013)";
$String2 = "Free Free Text Text(2000 min)-Ret - (Active Date: 12-03-2011 , End Date: )";
I want $String1
to replace to: "Text Text"
and $String2
to "Free Free Text Text(2000 min)-Ret"
Upvotes: 0
Views: 1095
Reputation: 57690
This will do.
$pattern = '/\s*\-\s*\(\s*Active[^\)]+\)/';
$String1 = preg_replace($pattern, '', $String1);
$String2 = preg_replace($pattern, '', $String2);
Upvotes: 3
Reputation: 2227
substr( $string, 0, strpos($string," - (") );
Edit: After, you may use trim()
for stripping whitespaces from begin and end of the string.
Upvotes: 0
Reputation: 4397
You'll want to use something like:
preg_replace('/\(Active.*?\)/','(text Text)',$String1);
Note that the parenthesis need to be escaped with \
so they are interpreted as literals, not as control characters.
Upvotes: 0