note 61769 deleted from function.strpos by danbrown

From: Date: Sun, 17 May 2009 16:36:14 +0000
Subject: note 61769 deleted from function.strpos by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154861@lists.php.net to get a copy of this message
Note Submitter: fox_galih at yahoo dot co dot uk ---- Be carefull when your searching position is in first index. For example: $newsbody = "<p>This is paragraph</p>"; if( strpos( $newsbody, "<p>" ) == 0 ) { // do something } when strpos returns FALSE, this "if block" will be executed by PHP, because FALSE also has 0 value. So, you have to make it a little bit longer of code: $pos = strpos( $newsbody, "<p>" ); if ( $pos != FALSE ) { $pos = strpos( $newsbody, "<p>" ); if( $pos == 0 ) $newsbody = substr( $newsbody, 3 ); }

« previous php.notes (#154861) next »