note 38330 deleted from function.strrpos by didou

From: Date: Mon, 22 Jan 2007 07:41:08 +0000
Subject: note 38330 deleted from function.strrpos by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-122030@lists.php.net to get a copy of this message
Note Submitter: cagret at yahoo dot com Reason: useless ---- This functions could be helpful: <?php /** * @access public * @package String * @static */ class String { /** * Replace only the first occurence of the search string with the replacement string * @param string $string * @param string $search * @param string $replace * @return string * @access public */ function replaceFirst($string, $search, $replace) { $pos = strpos($string, $search); if (is_int($pos)) { $len = strlen($search); return substr_replace($string, $replace, $pos, $len); } return $string; } /** * Replace only the last occurence of the search string with the replacement string * @param string $string * @param string $search * @param string $replace * @return string * @access public */ function replaceLast($string, $search, $replace) { $pos = false; if (is_int(strpos($string, $search))) { $endPos = strlen($string); while ($endPos > 0) { $endPos = $endPos - 1; $pos = strpos($string, $search, $endPos); if (is_int($pos)) { break; } } } if (is_int($pos)) { $len = strlen($search); return substr_replace($string, $replace, $pos, $len); } return $string; } } ?>

« previous php.notes (#122030) next »