Reply to Re: question about changing a string :)

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация