06-10-2008, 03:01 PM
|
#4 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Salathe doesn't sleep. He's out there, maintaining the balance.
It might be harder to read if you're not first familiar with the ternary operator. It's a really handy shorthand for a basic IF statement.
PHP Code:
/* in english */ if (statement evaluates true) ? 'then do this' : 'otherwise do this';
/* in PHP */
// echo's "$somevar is set" if true echo (isset($somevar)) ? '$somevar is set' : '$somevar is not set';
// sets $isSet to true, if true $isSet = (isset($somevar)) ? true : false;
// sets $answer to "$somevar is less than or equal to $othervar" if true $answer = ($somevar <= $othervar) ? '$somevar is less than or equal to $othervar' : '$othervar is less than $somevar';
So what Salathe has done;
If $pos = strpos($text0, '(')) doesn't return false, than that means '(' was found somewhere in $text0 and the statement evaluates to true. If it evaluates to true, the ternary executes the code found after the ? and before the :, which in this case returns a substr of $text0, from the start of the string to the position where the first ( was found. If it evaluates to false, it executes the code found after the : and before the end of the block, which in this case would return a value of FALSE.
-m
|
|
|
|