question about changing a string :)

Hi, I want to replace every instance of X with some random letter from
A thru Z. How could this be expressed in this format:

$string = $updatedstringwithreplacements

:)
alkalsa [ Fr, 12 Januar 2007 08:19 ] [ ID #1593554 ]

Re: question about changing a string :)

alkalsa [at] gmail.com wrote:
> Hi, I want to replace every instance of X with some random letter from
> A thru Z. How could this be expressed in this format:
>
> $string = $updatedstringwithreplacements
>
> :)


If they can stay the same capital all over:
$updatedstringwithreplacements = str_replace('X',chr(rand(65,90)),$string);


For a different (or random, zo it could be the same) capital:
<?php
function return_capital(){
return chr(rand(65,90));
}
$string = "aslkXdjfhdsaf;ljnXg;afjafhX;alskjdf;iasdXhfjkaXsXXXdf;kaXXs fda";
$updatedstringwithreplacements =
preg_replace_callback('/X/','return_capital',$string);
?>
--
Rik Wasmus
Rik [ Fr, 12 Januar 2007 09:51 ] [ ID #1593558 ]
PHP » alt.php » question about changing a string :)

Vorheriges Thema: Att: J.O Aho
Nächstes Thema: Best PHP IDE ?