|  | Posted by gosha bine on 09/24/07 13:46 
Henri wrote:> Hello,
 >
 > I am trying to split a string that contains parentheses; the aim here is
 > to keep the part that's before the opening parenthese:
 >
 > the string (quoted here) is "36 (72 cm)"
 > First I want to know if the string contains at least an openning
 > parenthese; if it does, I split it and extract the first token (ie "36 ").
 > My code follows
 >
 > if (preg_match("/\(/", $sPermutationName)) {
 > 	$tokens = explode("\(", $sPermutationName);
 > 	$sPermutationName = $tokens[0];
 > }
 >
 > but that does not work. Would anyone care to enlighten me on this one?
 
 Hi Henri
 
 regular expressions would be on overkill here.
 
 strtok($a, "(")
 
 does exactly what you want - returns a portion of the string before "(".
 If there's no "(" , the whole string will be returned.
 
 
 
 
 --
 gosha bine
 
 extended php parser ~ http://code.google.com/p/pihipi
 blok ~ http://www.tagarga.com/blok
  Navigation: [Reply to this message] |