Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
go ahead... be a heretic
 
PerlMonks  

Re: CGI Script for Reading Newest Nodes

by epoptai (Curate)
on Jun 14, 2001 at 03:57 UTC ( [id://88287]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to CGI Script for Reading Newest Nodes

Looking good voyager. Here's a small patch that will convert any UTF-8 extended ascii from XML::Parser to latin1 so odd nodetitles or usernames look right.

Example nodetitle from today's new nodes:

Before: Reactionary Coding—One-Shot Programs
After : Reactionary Coding—One-Shot Programs

Add this conversion subroutine:

sub UTF8_latin1 { # UTF-8 to latin1 regex from XML::TiePYX (thanks to mirod) my($text) = @_; $text =~ s{([\xc0-\xc3])(.)}{ my $hi = ord($1); my $lo = ord($2); chr((($hi & 0x03) <<6) | ($lo & 0x3F)) }ge; return $text; }
Add two lines to the foreach loop in sub html_by_type:
foreach my $node (@$nodes) { $node->{cdata} = UTF8_latin1($node->{cdata}); # ADDED my $link = $q->a({-href => "$url_base$node->{node_id}"}, $node +->{cdata}); my $node_text = $q->li($link); my $author = $authors->{$node->{author_user}}; $author = UTF8_latin1($author); # ADDED $node_text .= ('&nbsp;' x 2) . $q->small(" by $author") if $SH +OW_AUTHOR; print $node_text; }
Enjoy.

--
Check out my Perlmonks Related Scripts like framechat, reputer, and xNN.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://88287]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.