Jump to content

Parse a string and replace each character in it with an image


Damage

Recommended Posts

Ok I'm kind of new to php so this may be a nub question but i haven't been

able to find an answer to it yet.. here it is..

 

I'm trying to put a date on a news post but instead of just typing it in as

normal text i want to be able to type it in a string then have a function

go over the string and replace each number with a pre-made image

 

Thanks.

$string = 'string';
$letters = explode('', $string); // this gives you an array with one letter in each element
$images = array();
foreach($letters as $letter)
{
  $images[] = '<img src="' . $letter . '.jpg" />';
}
$images_string = implode($images);
echo $images_string;

I just got it working =D

 

function DateReplace ($ReplaceText)
{
$Numbers=array(
	'1' => "<img src='/images/date/1.gif' />",
	'2' => "<img src='/images/date/2.gif' />",
	'3' => "<img src='/images/date/3.gif' />",
	'4' => "<img src='/images/date/4.gif' />",
	'5' => "<img src='/images/date/5.gif' />",
	'6' => "<img src='/images/date/6.gif' />",
	'7' => "<img src='/images/date/7.gif' />",
	'8' => "<img src='/images/date/8.gif' />",
	'9' => "<img src='/images/date/9.gif' />",
	'0' => "<img src='/images/date/0.gif' />"
);

$Date=str_replace(array_keys($Numbers), array_values($Numbers), $ReplaceText);

return $Date;	
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.