PHP 8.5.0 Alpha 4 available for testing

Voting

: max(nine, five)?
(Example: nine)

The Note You're Voting On

dot dot dot dot dot alexander at gmail dot com
17 years ago
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 */
?>

<< Back to user notes page

To Top