You are here: Re: question about changing a string :) « All PHP « IT news, forums, messages
Re: question about changing a string :)

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

 

Navigation:

[Reply to this 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

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