
Originally Posted by
marain
... The second condition is that $subhead[$here] does not contain the word "Click". My PHP source code tests for those conditions.
[ ... ]
PHP Code:
$bigBoole = strpos( $subhead[$here], $click, 0);
if ( $subhead[$here] && $bigBoole != 0 && $bigBoole != '0');
actually, you're checking that $subhead[$here] does contain "Click", but does not start with "Click."
strpos returns either FALSE (if $needle was not found), or an integer (the location of the first $needle found).
PHP Code:
$result = strpos( "_____ here!","Click" );
// $result is FALSE
// ($result != 0) is FALSE
// ($result !='0') is redundant (but also FALSE)
$result = strpos( "Click here!","Click" );
// $result is 0
// ($result != 0) is FALSE
// ($result !='0') is redundant (but also FALSE)
$result = strpos( " Click here!","Click" );
// $result is 1
// ($result != 0) is TRUE
// ($result !='0') is redundant (but also TRUE)
don't check for 0 (or "0"). Check for FALSE:
PHP Code:
if( $bigBoole === FALSE ){
// "Click" was not found. (anywhere in the string.)
// note we use "===" ("exactly equal"), and not "==" ("equivalent").
// the opposite of this is "!==" ("not exactly equal").
}
---------------------------
But before any of this will work, you need to clean up your code:
PHP Code:
if ( $subhead[$here] && $bigBoole != 0 && $bigBoole != '0');
// this is meaningless. You're checking the condition, but doing nothing either way.
// I think you meant to do this...?
if( $subhead[$here] && $bigBoole != 0 && $bigBoole != '0'){
echo ' - ' . $subhead[$here];
}
// lesson: always use brackets. they will help you:
// easily identify what your logic is doing
// easily identify where you've made mistakes in syntax.
PHP Code:
// HOWEVER, to get the result you want, do it this way instead:
if( !empty( $subhead[$here] ) && $bigBoole === FALSE ){
// not empty.
// no "Click".
echo ' - '. $subhead[$here];
}
Bookmarks