note 89139 modified in function.str-replace by danbrown

From: Date: Tue, 24 Feb 2009 02:07:30 +0000
Subject: note 89139 modified in function.str-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151040@lists.php.net to get a copy of this message
In order to create nicer urls i use this simple function: <?php function niceURL($string) { $que = array( 'á','é','í','ó','ú','Á','É','Í','Ó','Ú','ñ','Ñ',' ' ); $por = array( 'a','e','i','o','u','A','E','I','O','U','n','n','-' ); return strtolower( str_replace( $que,$por,$string ) ); } ?> For string "Hello Cruel World" This will return "hello-cruel-world" However once i wrote this: <?php function niceURL($string) { //changing the place of ' ' by '-' to the begining $que = array( ' ','á','é','í','ó','ú','Á','É','Í','Ó','Ú','ñ','Ñ' ); $por = array( '-','a','e','i','o','u','A','E','I','O','U','n','n' ); return strtolower( str_replace( $que,$por,$string ) ); } ?> And for "Hello Cruel World" This will return "hellocruelworld" I have no idea why but it made me crazy for a while, --was-- In order to create nicer urls i use this simple function: function niceURL($string) { $que = array( 'á','é','í','ó','ú','Á','É','Í','Ó','Ú','ñ','Ñ',' ' ); $por = array( 'a','e','i','o','u','A','E','I','O','U','n','n','-' ); return strtolower( str_replace( $que,$por,$string ) ); } For string "Hello Cruel World" This will return "hello-cruel-world" However once i wrote this: function niceURL($string) { //changing the place of ' ' by '-' to the begining $que = array( ' ','á','é','í','ó','ú','Á','É','Í','Ó','Ú','ñ','Ñ' ); $por = array( '-','a','e','i','o','u','A','E','I','O','U','n','n' ); return strtolower( str_replace( $que,$por,$string ) ); } And for "Hello Cruel World" This will return "hellocruelworld" I have no idea why but it made me crazy for a while, http://php.net/manual/en/function.str-replace.php

« previous php.notes (#151040) next »