|
Posted by Rik on 01/12/07 08:51
alkalsa@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;kaXXsfda";
$updatedstringwithreplacements =
preg_replace_callback('/X/','return_capital',$string);
?>
--
Rik Wasmus
[Back to original message]
|