note 42595 modified in function.str-replace by aidan
| From: | aidan@php.net | Date: | Sat, 26 Jun 2004 13:58:24 +0000 |
| Subject: | note 42595 modified in function.str-replace by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-71766@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.
--was--
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.
http://php.net/manual/en/function.str-replace.php