note 67296 added to function.strrchr

From: Date: Wed, 07 Jun 2006 02:55:42 +0000
Subject: note 67296 added to function.strrchr
Groups: php.notes 
Request: Send a blank email to php-notes+get-113422@lists.php.net to get a copy of this message
to: repley at freemail dot it the code works very well, but as i was trying to cut script names (e.g.: $_SERVER["SCRIPT_NAME"] => /index.php, cut the string at "/" and return "index.php") it returned nothing (false). i've modified your code and now it works also if the needle is the first char. - regards from germany <?php //strxchr(string haystack, string needle [, bool int leftinclusive [, bool int rightinclusive ]]) function strxchr($haystack, $needle, $l_inclusive = 0, $r_inclusive = 0){ if(strrpos($haystack, $needle)){ //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. return array($left, $right); } else { if(strrchr($haystack, $needle)) return array('', substr(strrchr($haystack, $needle), $r_inclusive)); else return false; } } ?> ---- Server IP: 217.13.201.10 Probable Submitter: 84.149.168.182 ---- X-Spam-Status: No, hits=4.0 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, TO_HAS_SPACES,TO_MALFORMED autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.strrchr.php Edit -- http://master.php.net/note/edit/67296 Del: integrated -- http://master.php.net/note/delete/67296/integrated Del: useless -- http://master.php.net/note/delete/67296/useless Del: bad code -- http://master.php.net/note/delete/67296/bad+code Del: spam -- http://master.php.net/note/delete/67296/spam Del: non-english -- http://master.php.net/note/delete/67296/non-english Del: in docs -- http://master.php.net/note/delete/67296/in+docs Del: other reasons-- http://master.php.net/note/delete/67296 Reject -- http://master.php.net/note/reject/67296 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#113422) next »