|
Posted by Henri on 09/24/07 14:42
On Mon, 24 Sep 2007 06:31:28 -0700, Captain Paralytic wrote:
> On 24 Sep, 13:52, Henri <h...@dontbother.fu> 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?
>
> "does not work", ahh how helpful! That tells us exactly what you are
> actually seeing - NOT!!!
>
mmh... forgive me. What I clumsily tried to mean is that the preg_match
did not seem to see any parenthese in the string and therefore did not
execute the two following statements.
> As a matter of interest, why are you exploding on "\(", when \ doesn't
> appear in the target string?
because I thought that escaping the parenthese would avoid a compilation
error due to the code's being misinterpreted (ie: reporting a parenthese
mismatch).
Anyway, I think I have a solution now.
Navigation:
[Reply to this message]
|