On Tue, Sep 27, 2016 at 3:47 PM, CRPence <crpbottle@xxxxxxxxx> wrote:
If the code point 0x0A is required to be stored in the EBCDIC application
data [to avoid changing the application], then consider:
That 0x0A is the Repeat (RPT) control character in EBCDIC, into which the
Single Shift Two (SS2) control character should translate from the code
point 0x8E in ASCII.
I would emphasize *should*. In reality, "ASCII" is not some universal,
monolithic standard. There are many, many variants, especially when it
comes to 8-bit values. Not all flavors of ASCII have an 0x8E defined,
and some common variants have it defined as something else (notably
CP437 and CP1252). Even UTF-8, the dominant encoding on the Web and
one that most people think "will handle everything", will have
problems if you try the 0x8E "trick". (You would need to use 0xC28E
instead.)
It is likely that the ASCII flavor being used here is CP819, and in
that case, I believe the 0x8E character will be translated as desired
to 0x0A. But it's worth being aware of the other ASCII variants,
especially since we're talking about PHP.
Speaking of PHP, the language itself supports various encodings, so if
the 0x8E trick doesn't work, maybe try forcing it to ISO-8859-1
(another name for CP819). I don't use PHP myself, so I don't know how
to go about doing this. I also don't know if PHP has any EBCDIC
support (which could simplify things), but I would guess that it
doesn't.
A similarly improper entrenchment ;-) might be able to overcome that
issue; try the following revision to the [prepared statement code
presented by OP]:
$temp =
"Name: " . $name . x'8E' .
"Email Address: " . $emailAddress . x'8E' .
"Phone Number: " . $phoneNumber . x'8E' .
"Message: " . $message . x'8E' .
"HTTP_REFERRER: " . $_SERVER[ 'HTTP_REFERER' ]; // Notes
$nnotes = str_replace( " ", "", $temp );
I guess it's a quibble, but I would personally just stick to the
original code for the expression which assigns $temp, and then do the
replacement at the end:
$nnotes = str_replace( " \n", "\x8e", $temp );
This is a "lighter touch", preserving the semantic newlines and
reducing the appearance of magic constants to the bare minimum.
If you do use Chuck's expression, I think you just assign it directly
to $nnotes and dispense with $temp. Chuck has destroyed the leading
spaces (embedded in the string) at the beginning of each line, thus
obviating the need for the replacement at the end.
John Y.
As an Amazon Associate we earn from qualifying purchases.