note 68809 added to function.strrchr

From: Date: Fri, 11 Aug 2006 13:57:20 +0000
Subject: note 68809 added to function.strrchr
Groups: php.notes 
Request: Send a blank email to php-notes+get-115794@lists.php.net to get a copy of this message
Final get file name and extension into an array with or without dot, using strrchr and strrchr_reverse. Note our use of !==. Now work if the position of $needle in $haystack was the 0th (first) character like ".htaccess" <? //strxchr(string haystack, string needle [, bool int leftinclusive [, bool int rightinclusive ]]) function strxchr($haystack, $needle, $l_inclusive = 0, $r_inclusive = 0){ //Note our use of !==. Now work if the position of $needle in $haystack was the 0th (first) character. if(strrpos($haystack, $needle) !== false){ //Everything before last $needle in $haystack. $left = substr($haystack, 0, strrpos($haystack, $needle) + $l_inclusive); //Switch value of $r_inclusive from 0 to 1 and viceversa. $r_inclusive = ($r_inclusive == 0) ? 1 : 0; //Everything after last $needle in $haystack. $right = substr(strrchr($haystack, $needle), $r_inclusive); //Return $left and $right into an array. $a = array($left, $right); return $a; }else{ return false; } } ?> Repley ---- Server IP: 213.92.11.19 Probable Submitter: 84.222.146.10 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.strrchr.php Edit -- https://master.php.net/note/edit/68809 Del: integrated -- https://master.php.net/note/delete/68809/integrated Del: useless -- https://master.php.net/note/delete/68809/useless Del: bad code -- https://master.php.net/note/delete/68809/bad+code Del: spam -- https://master.php.net/note/delete/68809/spam Del: non-english -- https://master.php.net/note/delete/68809/non-english Del: in docs -- https://master.php.net/note/delete/68809/in+docs Del: other reasons-- https://master.php.net/note/delete/68809 Reject -- https://master.php.net/note/reject/68809 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115794) next »