Replacing every character in a string with individual <img> tags
Replacing every character in a string with individual <img> tags
am 11.09.2007 00:05:26 von PaddyPerl
Hi everybody!
OK, so what I want to do is to display a string in html as images
rather than text. On the server I have individual image files a.gif,
b.gif, c.gif ... 0.gif, 1.gif, 2.gif, 3.gif etc...
So if the string is Hello, I would like to get the following output:





I would like to translate all characters, numbers and special
characters as well.
Shouldn't this be quite easy? I just don't know how to do it though...
Thanks a lot for your help!
/Paddy
Re: Replacing every character in a string with individual <img> tags
am 11.09.2007 00:10:35 von Paul Lalli
On Sep 10, 6:05 pm, PaddyP...@gmail.com wrote:
> Hi everybody!
>
> OK, so what I want to do is to display a string in html as images
> rather than text. On the server I have individual image files a.gif,
> b.gif, c.gif ... 0.gif, 1.gif, 2.gif, 3.gif etc...
> So if the string is Hello, I would like to get the following output:
> 




>
> I would like to translate all characters, numbers and special
> characters as well.
>
> Shouldn't this be quite easy? I just don't know how to do it
> though...
In general, you should always post your best attempt when asking for
help.
However, I'm bored.
$string = s/(.)/
/g;
Paul Lalli
Re: Replacing every character in a string with individual <img> tags
am 11.09.2007 01:47:22 von usenet
On Sep 10, 3:10 pm, Paul Lalli wrote:
> $string = s/(.)/
/g;
Surely Paul meant
$string =~ s/(.)/
/g;
But you need to consider if double-quote is one of the "special
characters" that you want to allow...
--
David Filmer (http://DavidFilmer.com)
Re: Replacing every character in a string with individual <img> tags
am 11.09.2007 01:53:16 von Paul Lalli
On Sep 10, 7:47 pm, use...@DavidFilmer.com wrote:
> On Sep 10, 3:10 pm, Paul Lalli wrote:
>
> > $string = s/(.)/
/g;
>
> Surely Paul meant
> $string =~ s/(.)/
/g;
Took me five reads to realize you're pointing out the fact that I used
= where I meant =~
Thanks,
Paul Lalli
Re: Replacing every character in a string with individual <img> tags
am 11.09.2007 01:59:54 von Gunnar Hjalmarsson
usenet@DavidFilmer.com wrote:
>
> $string =~ s/(.)/
/g;
>
> But you need to consider if double-quote is one of the "special
> characters" that you want to allow...
Special? In what sense?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Re: Replacing every character in a string with individual <img> tags
am 11.09.2007 02:07:06 von PaddyPerl
> $string =3D~ s/(.)/
/g;
>
Great! Thanks alot to all of you!
But... I've now realized I have another problem...
With special characters such as Ä, I decided to go for filenames such
as AE.gif to avoid problems with encoding, and first tried a
$string =3D~ s/Ä/AE/g;
prior to the above, but then of course I'm left with two images (A and
E) instead of the desired AE.gif. Is there a way to avoid a lot of if
statements here?
Paddy
Re: Replacing every character in a string with individual <img> tags
am 11.09.2007 02:30:39 von Gunnar Hjalmarsson
PaddyPerl@gmail.com wrote:
>> $string =~ s/(.)/
/g;
>
> Great! Thanks alot to all of you!
> But... I've now realized I have another problem...
> With special characters such as Ä, I decided to go for filenames such
> as AE.gif to avoid problems with encoding, and first tried a
> $string =~ s/Ä/AE/g;
> prior to the above, but then of course I'm left with two images (A and
> E) instead of the desired AE.gif. Is there a way to avoid a lot of if
> statements here?
Use a hash.
my %special = (
'Ä' => 'AE',
'Ö' => 'OE',
);
s/(.)/'
'/eg;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Re: Replacing every character in a string with individual <img> tags
am 11.09.2007 05:53:08 von Peter Makholm
Gunnar Hjalmarsson writes:
> usenet@DavidFilmer.com wrote:
>>
>> $string =~ s/(.)/
/g;
>>
>> But you need to consider if double-quote is one of the "special
>> characters" that you want to allow...
>
> Special? In what sense?
In the senses that
probaly isn't parsed the intended
way by most HTML readers.
//Makholm