Created
September 21, 2013 21:37
-
-
Save thecrypticace/6654461 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header("Content-Type:text/plain"); | |
/* Escaping Challenge: Make a PHP script that (Z:) generates JavaScript code | |
* that generates an HTML page containing a PHP script that (goto Z) */ | |
/* The purpose of this challenge is to demonstrate how complicated escaping can | |
* get when you're trying to combine 4 different languages (PHP, JavaScript, | |
* HTML, and string literals). */ | |
function js_string_escape($data) | |
{ | |
return implode(array_map(function($s){ | |
return (ctype_alnum($s) ? $s : sprintf("\\x%02X", ord($s))); | |
}, str_split(htmlentities($data,ENT_QUOTES)))); | |
} | |
echo 'document.body.innerHTML="'.js_string_escape(file_get_contents(__FILE__)).'";'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment