1

I'm trying to get zend engine to interpret my PHP scripts as UTF-16BE. On a PHP 5.4 setup, I have the following settings in my PHP.ini file:

zend.script_encoding = UTF-16BE
zend.detect-unicode = 0
zend.multibyte = On

This is my script index.php:

<?php echo '1';

The file is a total of 32 bytes, saved using UTF-16BE:

FE FF // BOM
00 3C 00 3F 00 70 00 68 00 70 00 20 // <?php 
00 65 00 63 00 68 00 6F 00 20 // echo
00 27 00 31 00 27 // '1'
00 3B // ;

However the script is not working; the output is <?php echo '1'; instead of 1.

So I tried removing the BOM:

00 3C 00 3F 00 70 00 68 00 70 00 20 // <?php 
00 65 00 63 00 68 00 6F 00 20 // echo
00 27 00 31 00 27 // '1'
00 3B // ;

But the output is still <?php echo '1'; instead of 1.

Then I tried encoding the start sequence — <?php — in ASCII, while the remaining characters remain UTF-16BE encoded:

3C 3F 70 68 70 20 // <?php 
00 65 00 63 00 68 00 6F 00 20 // echo
00 27 00 31 00 27 // '1'
00 3B // ;

The engine seems to be able to interpret the PHP script now, but it's still not working:

Warning: Unexpected character in input: ' in C:\xampp\htdocs\test\index.php on line 1

Warning: Unexpected character in input: ' in C:\xampp\htdocs\test\index.php on line 1

Parse error: syntax error, unexpected 'c' (T_STRING) in C:\xampp\htdocs\test\index.php on line 1

How does zend.script_encoding work?

How can we get the engine to interpret scripts written in a specific encoding?

Community
  • 1
  • 1
Pacerier
  • 86,231
  • 106
  • 366
  • 634
  • 1
    ***"When ISO-8859-1 imcompatible encoding is used, both zend.multibyte and zend.script_encoding must be used."*** - TFM – deceze Oct 27 '14 at 09:16
  • Any reason to do this? How about utf-8? – Karoly Horvath Oct 27 '14 at 09:30
  • @KarolyHorvath, Yes, I'm testing if the engine is working as expected. Throwing UTF-8 everywhere and anywhere such that things *seem* to work doesn't really mean things are closed to exploits. – Pacerier Oct 27 '14 at 09:32
  • @Pacerier: "Thanks it's working now" - "things seem to work doesn't really mean things are closed to exploits" :DDDD (note: no need to reply) – Karoly Horvath Oct 27 '14 at 09:35
  • @KarolyHorvath, Yea one step at a time. I'm getting alot of weird behavior here, see http://stackoverflow.com/q/26585015/632951 . Perhaps we should blame it on the terseness of PHP docs. – Pacerier Oct 27 '14 at 10:02
  • @deceze, Btw, do you happen to know why the setting `detect-unicode` isn't working? http://stackoverflow.com/questions/26585015/how-to-ensure-that-php-respects-zend-script-encoding-setting – Pacerier Oct 31 '14 at 22:16

0 Answers0