Skip to content

Instantly share code, notes, and snippets.

@rquadling
Last active August 29, 2015 14:18
Show Gist options
  • Save rquadling/068ac672d97e2e3e6cfa to your computer and use it in GitHub Desktop.
Save rquadling/068ac672d97e2e3e6cfa to your computer and use it in GitHub Desktop.
Testing PHP and unicode output.
@ECHO OFF
SETLOCAL
REM Force UTF8
chcp 65001
REM Call the script again, as chcp doesn't affect THIS context.
CALL :UTF8ready %0
GOTO Done
:UTF8Ready
ECHO.
SET Text=FRáD
ECHO ====== From a batch file
ECHO %Text%
ECHO ==OK==
ECHO.
ECHO ====== From a batch file, captured to a log file and displayed
ECHO %Text%>%1.log
TYPE %1.log
ECHO ==OK==
ECHO.
REM Build the PHP -r string
SET PHP_R="echo '%Text%' . PHP_EOL . var_export('%Text%', true) . PHP_EOL; var_dump('%Text%');"
ECHO Going to call.
ECHO php -r %PHP_R%
ECHO.
ECHO ====== Via php -r
php -r %PHP_R%
ECHO =????= **** NON UNICODE DISPLAYED ****
ECHO.
ECHO ====== Via php -r, captured to a log file and displayed
php -r %PHP_R%>%1.log
TYPE %1.log
ECHO =????= **** NON UNICODE DISPLAYED ****
ECHO.
REM Build the PHP Script
ECHO ^<?php echo '%Text%' . PHP_EOL . var_export('%Text%', true) . PHP_EOL; var_dump('%Text%');>%1.php
ECHO Going to execute the PHP script
TYPE %1.php
ECHO.
ECHO ====== From a php script
php -f %1.php
ECHO =????= **** AN EXTRA A IN THE VAR_DUMP() ****
ECHO =????= **** EXTRA LINE DISPLAYED IN THE OUTPUT ****
ECHO.
ECHO ====== From a php script, captured to a log file and displayed
php -f %1.php>%1.log
TYPE %1.log
ECHO ==OK==
ECHO.
ECHO ====== From a php script via hexdump -C
php -f %1.php|hexdump -C
ECHO ==OK==
ECHO.
ECHO ====== From a php script via hexdump -C, captured to a log file and displayed
php -f %1.php|hexdump -C>%1.log
TYPE %1.log
ECHO ==OK==
ECHO.
DEL /q %1.log
DEL /q %1.php
GOTO :EOF
:Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment