Re: regex for emoticon codes

From: Date: Tue, 09 Jul 2002 08:54:16 +0000
Subject: Re: regex for emoticon codes
Groups: php.general 
Request: Send a blank email to php-general+get-106314@lists.php.net to get a copy of this message
>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

« previous php.general (#106314) next »