Hi,
Thanks for the replies :) I was expecting an email response - so good thing I checked back to see if there were any replies :)
I've tried:
sub GetAdvertsForLink {
use strict;
use warnings;
use utf8;
binmode STDOUT, ':encoding(UTF-8)';
$_ = 'été';
my $desc = "test 123 un été à Tanger. élargir elargir ete";
$desc =~ s|\b\Q$_|<a href="url">$_</a>|sg;
print "FOO" . $desc;
}
You can see this in operation here:
http://www.sudimedia.com/cgi-bin/link/page.cgi?g=Detailed%2F3.html;d=1
The problem now seems:
1) Its doesn't link at all
2) The charachters come up as weird charachters (in FF), and blank spaces in IE 7)
If this is any help - the whole function is:
#<%Plugins::SponsorText::GetAdvertsForLink($Description,$category_id)%
+>
sub GetAdvertsForLink2 {
use locale;
my $desc = $_[0];
my $link_id = $_[1];
my $cat_tbl = $DB->table('CatLinks');
$cat_tbl->select_options('LIMIT 1');
my $cat_id = $cat_tbl->select( ['CategoryID'] , { LinkID => $link_
+id } )->fetchrow;
my $cond = new GT::SQL::Condition;
$cond->add('CatIDs','LIKE',"%,$cat_id,%");
$cond->add('CatIDs','LIKE',"%,$cat_id");
$cond->add('CatIDs','LIKE',"$cat_id,%");
$cond->add('CatIDs','LIKE',"$cat_id");
$cond->bool('OR');
my @words;
print $IN->header;
# print qq|GOT CAT ID: $cat_id|;
# use Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset);
+
my $sth = $DB->table('SponsorLinkText')->select( $cond ) || die $GT
+::SQL::error;
while (my $hit = $sth->fetchrow_hashref) {
my (@words) = split /,/, $hit->{Words};
$hit->{Target} ||= '_blank';
foreach (@words) {
print qq|Looking for "$_" in "$desc" <br />\n|;
if ($hit->{TheText}) {
$desc =~ s|\b$_|<a href="$hit->{LinkURL}" title="$hit->{Th
+eText}" target="$hit->{Target}">$_</a>|sg;
} else {
$desc =~ s|\b$_|<a href="$hit->{LinkURL}" target="$hit->{T
+arget}">$_</a>|sg;
}
}
}
return $desc;
}
Its for a program called Gossamer Links. Basically, this is how it works:
1) Grabs entries from the SponsorLinkText table, and gets the words to link/the link itself, and a few other bits of info
2) Split the words up - and then does:
foreach (@words) {
print qq|Looking for "$_" in "$desc" <br />\n|;
if ($hit->{TheText}) {
$desc =~ s|\b$_|<a href="$hit->{LinkURL}" title="$hit->{Th
+eText}" target="$hit->{Target}">$_</a>|sg;
} else {
$desc =~ s|\b$_|<a href="$hit->{LinkURL}" target="$hit->{T
+arget}">$_</a>|sg;
}
}
(which basically links the words to their appropriate letters - at least in theory =))
TIA for any more suggestions.
Andy |