[Phpug] {Possible Spam} Re: Zend_feed and RTE
David McCarthy (kreators.net)
david at kreators.net
Fri May 9 14:29:25 IST 2008
I am very disappointed with this very, very poor standard of coding.
Put a bit of effort in lads, and // where are your comments !
----------------------------------------
From: Kae Verens <kae at webworks.ie>
Sent: 09 May 2008 14:02
To: Irish PHP User Group <phpug at lists.iephpug.org>
Subject: {Possible Spam} Re: [Phpug] Zend_feed and RTE
the solution:
<?php
function unichr($c) {
if ($c <= 0x7F) {
return chr($c);
} else if ($c <= 0x7FF) {
return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
} else if ($c <= 0xFFFF) {
return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F)
. chr(0x80 | $c & 0x3F);
} else if ($c <= 0x10FFFF) {
return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F)
. chr(0x80 | $c >> 6 & 0x3F)
. chr(0x80 | $c & 0x3F);
} else {
return false;
}
}
function unhtmlentities($string)
{
// replace numeric entities
$string = preg_replace('~&#x([0-9a-f]+);~ei',
'unichr(hexdec("\\1"))', $string);
$string = preg_replace('~&#([0-9]+);~e', 'unichr("\\1")', $string);
// replace literal entities
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}
echo unhtmlentities('test ? test');
Kae Verens wrote:
> Cormac Parle wrote:
>> Anyone know anything about zend_feed? Using it to process the news feed
>> from rte, but they have hex html entities (? for the euro symbol)
>> in the feed which are getting a bit mangled.
>
> there's no simple way at the moment. the usual suspects,
> html_entity_decode, et al. are simply not up to the task.
>
> i suspect that it's partly because the string encodes in hex instead of
> dec - html_entity_decode('?') works but
> html_entity_decode('?') doesn't.
>
> maybe you need to write a parser which converts hex2dec within the
> string before trying to decode?
>
> and yeah - the sig is a /bit/ excessive...
>
--
Kae Verens' signature
http://webworks.ie/ lead programmer
http://verens.com/ my blog
http://kfm.verens.com/ current project
--
this is Kae's signature's signature.
--
Kae's signature's signature does not get one though
_______________________________________________
Phpug mailing list
Phpug at lists.iephpug.org
http://lists.iephpug.org/mailman/listinfo/phpug
Member Map http://www.frappr.com/irishphpusersgroup/
Membership Planner Calendar: http://tinyurl.com/opjd5
More information about the Phpug
mailing list