note 61769 added to function.strpos

From: Date: Sat, 11 Feb 2006 09:42:51 +0000
Subject: note 61769 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-103501@lists.php.net to get a copy of this message
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 ); } ---- Server IP: 202.67.10.139 Probable Submitter: 219.83.113.25 (proxied: 202.154.63.42) ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61769 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61769&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61769&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61769&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61769&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61769&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61769&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61769&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61769&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#103501) next »