note 82039 added to function.strtr

From: Date: Tue, 25 Mar 2008 18:44:30 +0000
Subject: note 82039 added to function.strtr
Groups: php.notes 
Request: Send a blank email to php-notes+get-137569@lists.php.net to get a copy of this message
Here is the stritr I always needed... I wrote it in 15 minutes... But only after the idea struck me. Hope you find it helpful, and enjoy... <?php 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; } } $winner = min( $positions ); $key = array_search( $winner, $positions ); $product = ( substr( $product, 0, $winner ) . $positions[$key] . substr( $product, ( $winner + strlen($key) ) ) ); $pos1 = ( $winner + strlen( $positions[$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/82039 Del: integrated -- https://master.php.net/note/delete/82039/integrated Del: useless -- https://master.php.net/note/delete/82039/useless Del: bad code -- https://master.php.net/note/delete/82039/bad+code Del: spam -- https://master.php.net/note/delete/82039/spam Del: non-english -- https://master.php.net/note/delete/82039/non-english Del: in docs -- https://master.php.net/note/delete/82039/in+docs Del: other reasons-- https://master.php.net/note/delete/82039 Reject -- https://master.php.net/note/reject/82039 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137569) next »