...

View Full Version : Trim question



guvenck
02-04-2007, 10:39 PM
I would like to trim part of a string which looks like this:

$input = "This part should stay (Bracket) (Bracket2) (Bracket3)";

$output = "This part should stay";


Second and third brackets do appear sometimes and sometimes not.

I need the part before the first bracket and leave the space char out.

How can I do this?

mlseim
02-05-2007, 01:46 AM
Those are parenthesis, not brackets.

... and not sure what "leave the space char out" means ...



<?php
$input = "This part should stay {Bracket} {Bracket2} (Parenthesis1) (Parenthesis2)";

$pattern = "(\([^\)]*\))";
$output=eregi_replace($pattern,"",$input);
echo $output;
?>

guvenck
02-05-2007, 05:35 PM
Hi mlseim,

Sorry for "brackets", had no sleep for some time :)
Regular expressions again, need to work on them...

Leave the space char out:

in your code, $output is generated with a single space char at the end:



$output = "This part should stay ";


it probably needs something like this:



$output = substr($output, 0, -1);

mlseim
02-06-2007, 02:56 PM
So you did get it to work?
or you still need to get the last space removed?

not sure if this thread is finished.

guvenck
02-06-2007, 04:14 PM
Hi,

your code works as expected. I managed to remove the last space with the code I wrote. Thank you very much for your help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum