lk******@geocities.com wrote:
: I know I'm missing something obvious, but I looked hard at this page
: and did not see the format of the return specified:
:
http://us3.php.net/manual/en/function.ord.php
: >From the limited example I assume it is the decimal (not hex or binary)
: value of the character being returned?
The value returned is a number, it has no format unless you try to use it
as a string, then php would have to decide how to format the value.
: So long as the returned value is between 0 and 127, I can treat it as
: ascii?
As ascii yes, but as a character no.
ord() returns the numeric value of a byte, not the byte itself.
You can use the numeric value to do compares, but if you try to put the
numeric value into a string then you get the formatted number representing
the value, not the original byte.
If you want to get the original byte then you use chr() to convert the
numeric value into a byte that php can insert as-is into a string.
: If, for some reason, I had to restrict my output to ascii, then any
: time I encountered a value outside of 0 to 127, then I'd have to
: replace it with something in range?
Sure, I wouldn't use those words, but I guess you could say that.
: Despite all the terrific help I've gotten on comp.lang.php regarding
: this issue, my RSS feeds continue to fail when users write weblog posts
: in Microsoft Word and then copy and paste their post to a form and
: input that. So I'm resorting to severe measures. I don't care if I end
: up with a lot of garbage characters, that is fine, I just want the RSS
: feed to validate.
You need to do more than check ascii, you need to check for printable
characters. Binary data can contain ascii control codes, and those are
not allowed in xml.
Without checking all the details of the specs, a quick start would be to
check each character, and perhaps replace it with a . or ? when ever it
was below the value of a space char and greater than equal to 127
(decimal)
# untested
$len = strlen($the_input_data)
$space = ' ';
for ($i = 0; $i<$len; $i++)
{
$ch = substr($the_input_data,$i,1);
$value = ord($ch);
if ( $value >= ord($space) and $value < 127 )
{
echo chr($value);
}else
{
echo '?';
}
}
php has lots of functions that would do various part of this, and
perhaps even the entire thing, so personally I would expect to do this
without any of the above, but on the other hand, I know I sometimes need
to do it myself before I realize and properly appreciate what the
existing functions would be doing for me if I used them, so I show the
above.
--
This space not for rent.