note 42595 added to function.str-replace

From: Date: Sat, 22 May 2004 19:05:07 +0000
Subject: note 42595 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-69970@lists.php.net to get a copy of this message
Here's something I used to utilize str_replace in a script, by using it to replace text with graphic images.. say, if you had a counter or whatnot, and wanted a way to make the counter's results graphical: <? // For here, we're going to create a $ number .. $num = 56; // now, for the str_replace arrays. We'll need these to make the replacements. // digits to search for $nums = array ( "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" ); // images array to replace them with. $images = array ( "<img src=1.gif>", "<img src=2.gif>" , "<img src=3.gif>".. ); // continue with the <img src>'s with the number pattern above. // Now, for the function to do all the replacing. $final = str_replace ($nums, $images, $num); echo $final; ?> Quite simple, really. ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42595 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42595&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42595&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69970) next »