$cadena = "Esta es la cadena que quiero cambiar";
/*
.
.
.El código que lo convierte
.
.
*/
echo $cadenaconvertida;
Result: "This_is_the_string_I_want_to_change"
$cadena = "Esta es la cadena que quiero cambiar";
/*
.
.
.El código que lo convierte
.
.
*/
echo $cadenaconvertida;
Result: "This_is_the_string_I_want_to_change"
You have many alternatives in PHP .
strtr is used to replace characters consecutively, it replaces all occurrences of each character (single byte). This can show "unexpected" results when adding multiple characters since it interprets each character independently. For example:
string strtr ( string $string , string $from , string $to )
string strtr ( string $string , array $replace_pairs )
Response time (average): 40.9357118607 seconds
Reference: Here
preg_replace performs a regular expression search and replace.
mixed preg_replace ( mixed $pattern , mixed $replace , mixed $string [, int $limit = -1 [, int &$counter ]] )
Response time (average): 3.27423620224 seconds
Reference: Here
str_replace replaces all occurrences of the search string with the replacement string. This function returns a string or array with all occurrences of search in subject replaced with the given replacement value . search and replace can be a string or an array. If it is an array, an equivalent is made with the array with the lowest index for substitutions.
mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
Response time (average): 1.49082899094 seconds
Reference: Here