>i have something like
>$str = "sometext sometext [emoticon01] sometext [emoticon23] sometext";
>
>i would like to use regex to replace those codes into:
>sometext sometext /images/emot/01.gif sometext /images/emot/23.gif sometext
>
>all numerics after the code "emoticon" consisted of exactly 2 digits; and they
>are in the range from emoticon01 to emoticon30.
>
>i have spent the whole day starring at my crt and reading manpages plus
>examples. i achieved nothing but sore eyes.
>
>i would GREATLY-GREATLY appreciate if someone could gimme a code snippet on how
>to this sorta thing.
You're lucky. You don't have to strain your brain with Regex. :-)
<?php
for ($i = 1; $i <= 30; $i++){
$emoticon[] = '[emoticon' . sprintf("%02d", $i) . ']';
$images[] = '/images/emot/' . sprintf("%02d", $i) . '.gif';
}
$str = "sometext sometext [emoticon01] sometext [emoticon23] sometext";
echo str_replace($emoticons, $images, $str);
?>
http://php.net/str_replace
--
Like Music? http://l-i-e.com/artists.htm
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php