note 82051 added to function.strtr

From: Date: Wed, 26 Mar 2008 00:09:44 +0000
Subject: note 82051 added to function.strtr
Groups: php.notes 
Request: Send a blank email to php-notes+get-137583@lists.php.net to get a copy of this message
OK, I debugged the function (had some errors) Here it is: if(!function_exists("stritr")){ function stritr($string, $one = NULL, $two = NULL){ /* stritr - case insensitive version of strtr Author: Alexander Peev Posted in PHP.NET */ if( is_string( $one ) ){ $two = strval( $two ); $one = substr( $one, 0, min( strlen($one), strlen($two) ) ); $two = substr( $two, 0, min( strlen($one), strlen($two) ) ); $product = strtr( $string, ( strtoupper($one) . strtolower($one) ), ( $two . $two ) ); return $product; } else if( is_array( $one ) ){ $pos1 = 0; $product = $string; while( count( $one ) > 0 ){ $positions = array(); foreach( $one as $from => $to ){ if( ( $pos2 = stripos( $product, $from, $pos1 ) ) === FALSE ){ unset( $one[ $from ] ); } else{ $positions[ $from ] = $pos2; } } if( count( $one ) <= 0 )break; $winner = min( $positions ); $key = array_search( $winner, $positions ); $product = ( substr( $product, 0, $winner ) . $one[$key] . substr( $product, ( $winner + strlen($key) ) ) ); $pos1 = ( $winner + strlen( $one[$key] ) ); } return $product; } else{ return $string; } }/* endfunction stritr */ }/* endfunction exists stritr */ ---- Server IP: 69.147.83.197 Probable Submitter: 87.120.68.77 ---- Manual Page -- http://www.php.net/manual/en/function.strtr.php Edit -- https://master.php.net/note/edit/82051 Del: integrated -- https://master.php.net/note/delete/82051/integrated Del: useless -- https://master.php.net/note/delete/82051/useless Del: bad code -- https://master.php.net/note/delete/82051/bad+code Del: spam -- https://master.php.net/note/delete/82051/spam Del: non-english -- https://master.php.net/note/delete/82051/non-english Del: in docs -- https://master.php.net/note/delete/82051/in+docs Del: other reasons-- https://master.php.net/note/delete/82051 Reject -- https://master.php.net/note/reject/82051 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137583) next »