Thread Wert aufzählen (6 answers)
Opened by Gast at 2008-02-02 11:55

Gast Gast
 2008-02-02 11:55
#105479 #105479
Hallo,

ich habe eine Funktion für einen Chat zum umwandeln von Smileycodes:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
sub smileys_handler
{
my($self,$main,$text) = @_;

return if $main->{current_user}{nosmileys};

if (!exists($self->{smileys}))
{
$self->{smileys} = {};
foreach my $smiley (@{$main->{settings}{smileys}})
{
my $image = undef;
foreach (@$smiley)
{
if (!defined($image))
{
$image = $_;

my ($width,$height);
($width,$height) = @{$main->{settings}{images}{$image}} if defined($main->{settings}{images}{$image});
$width = (defined($width) ? " width=$width": "");
$height = (defined($height) ? " height=$height": "");

my $alt = $main->toHTML($smiley->[1]);
$image = "<img src=\"$main->{settings}{urls}{imagesurl}$image.gif\" border=0$width$height alt=\"$alt\">";
}
elsif ($_ ne '/hidden/')
{
$self->{smileys}{$main->toHTML($_)} = $image;
}
}
}
}

$$text =~ s/([^\s<>]+)/($self->{smileys}{$1}||$1)/ge;
}


Wie kann ich die Variable $smileys aufzählen, sodass die Ausgabe von $$text nur stattfindet, wenn nicht mehr als bsp. 5 Smilies im Text vorkommen?

Der erste Versuch war:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
if(!defined($smiley_count))
{
my $smiley_count = 0;
}
else
{
$smiley_count ++;
}

return if ($smiley_count >= 7);


Das klappt nur überhaupt nicht. Weiß jemand Rat?

Danke schonmal für eure Hilfe :)

View full thread Wert aufzählen