Reputation: 4819
I generated an obfuscated email using the Hive Logic Enkoder. I want to echo the result in PHP.
The problem is that it contains '
, "
, \\
and \\\\
, all of which mess up how PHP reads the string. How can I make PHP take this literally - escape the characters that need escaping, and un-escape the characters that don't?
So I want to:
echo '<script type="text/javascript">
//<![CDATA[
<!--
var x="function f(x){var i,o=\"\",ol=x.length,l=ol;while(x.charCodeAt(l/13)!" +
"=102){try{x+=x;l+=l;}catch(e){}}for(i=l-1;i>=0;i--){o+=x.charAt(i);}return " +
"o.substr(0,ol);}f(\")12,\\\",&.=1,p?3k`,gcheB8'Xfo!l720\\\\430\\\\120\\\\>X" +
"%E220\\\\230\\\\100\\\\530\\\\700\\\\RS,OT130\\\\630\\\\400\\\\230\\\\130\\" +
"\\530\\\\4[120\\\\700\\\\600\\\\010\\\\300\\\\520\\\\,a038t=68&>&2?120\\\\(" +
"*\\\"\\\\,v$>%!&+g030\\\\~$$2Wt\\\\I330\\\\400\\\\r\\\\JOGUImi3hu771\\\\tmt" +
"yq\\\"(f};o nruter};))++y(^)i(tAedoCrahc.x(edoCrahCmorf.gnirtS=+o;721=%y;i=" +
"+y)12==i(fi{)++i;l<i;0=i(rof;htgnel.x=l,\\\"\\\"=o,i rav{)y,x(f noitcnuf\")" ;
while(x=eval(x));
//-->
//]]>
</script>
';
Edit: here's the function I'm using now:
function supportEmail() {
$str = <<<'EOT'
<script type="text/javascript">
//<![CDATA[
<!--
var x="function f(x){var i,o=\"\",ol=x.length,l=ol;while(x.charCodeAt(l/13)!" +
"=102){try{x+=x;l+=l;}catch(e){}}for(i=l-1;i>=0;i--){o+=x.charAt(i);}return " +
"o.substr(0,ol);}f(\")12,\\\",&.=1,p?3k`,gcheB8'Xfo!l720\\\\430\\\\120\\\\>X" +
"%E220\\\\230\\\\100\\\\530\\\\700\\\\RS,OT130\\\\630\\\\400\\\\230\\\\130\\" +
"\\530\\\\4[120\\\\700\\\\600\\\\010\\\\300\\\\520\\\\,a038t=68&>&2?120\\\\(" +
"*\\\"\\\\,v$>%!&+g030\\\\~$$2Wt\\\\I330\\\\400\\\\r\\\\JOGUImi3hu771\\\\tmt" +
"yq\\\"(f};o nruter};))++y(^)i(tAedoCrahc.x(edoCrahCmorf.gnirtS=+o;721=%y;i=" +
"+y)12==i(fi{)++i;l<i;0=i(rof;htgnel.x=l,\\\"\\\"=o,i rav{)y,x(f noitcnuf\")" ;
while(x=eval(x));
//-->
//]]>
</script>
EOT;
echo $str;
}
But I get this error returned:
Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_END_HEREDOC or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN
Upvotes: 2
Views: 2791
Reputation: 180
The reason it is giving this error is because there is white space before the closing EOT. Remove all tabs or white space in front or behind it.
Upvotes: 0
Reputation: 2916
You could store the string in a file/database, and from there obtain it from there.
The problem from using nowdocs/heredocs commented in the other answers is that \\ is an escaped slash in both of them.
You can also use a nowdoc block and replace all occurrence of \ to \\.
Upvotes: 0
Reputation: 5853
Try using Heredoc:
$str = <<<EOD
<script type="text/javascript">
//<![CDATA[
<!--
var x="function f(x){var i,o=\"\",ol=x.length,l=ol;while(x.charCodeAt(l/13)!" +
"=102){try{x+=x;l+=l;}catch(e){}}for(i=l-1;i>=0;i--){o+=x.charAt(i);}return " +
"o.substr(0,ol);}f(\")12,\\\",&.=1,p?3k`,gcheB8'Xfo!l720\\\\430\\\\120\\\\>X" +
"%E220\\\\230\\\\100\\\\530\\\\700\\\\RS,OT130\\\\630\\\\400\\\\230\\\\130\\" +
"\\530\\\\4[120\\\\700\\\\600\\\\010\\\\300\\\\520\\\\,a038t=68&>&2?120\\\\(" +
"*\\\"\\\\,v$>%!&+g030\\\\~$$2Wt\\\\I330\\\\400\\\\r\\\\JOGUImi3hu771\\\\tmt" +
"yq\\\"(f};o nruter};))++y(^)i(tAedoCrahc.x(edoCrahCmorf.gnirtS=+o;721=%y;i=" +
"+y)12==i(fi{)++i;l<i;0=i(rof;htgnel.x=l,\\\"\\\"=o,i rav{)y,x(f noitcnuf\")" ;
while(x=eval(x));
//-->
//]]>
</script>
EOD;
Upvotes: 1
Reputation: 3931
echo <<<'EOT'
<script type="text/javascript">
//<![CDATA[
<!--
var x="function f(x){var i,o=\"\",ol=x.length,l=ol;while(x.charCodeAt(l/13)!" +
"=102){try{x+=x;l+=l;}catch(e){}}for(i=l-1;i>=0;i--){o+=x.charAt(i);}return " +
"o.substr(0,ol);}f(\")12,\\\",&.=1,p?3k`,gcheB8'Xfo!l720\\\\430\\\\120\\\\>X" +
"%E220\\\\230\\\\100\\\\530\\\\700\\\\RS,OT130\\\\630\\\\400\\\\230\\\\130\\" +
"\\530\\\\4[120\\\\700\\\\600\\\\010\\\\300\\\\520\\\\,a038t=68&>&2?120\\\\(" +
"*\\\"\\\\,v$>%!&+g030\\\\~$$2Wt\\\\I330\\\\400\\\\r\\\\JOGUImi3hu771\\\\tmt" +
"yq\\\"(f};o nruter};))++y(^)i(tAedoCrahc.x(edoCrahCmorf.gnirtS=+o;721=%y;i=" +
"+y)12==i(fi{)++i;l<i;0=i(rof;htgnel.x=l,\\\"\\\"=o,i rav{)y,x(f noitcnuf\")" ;
while(x=eval(x));
//-->
//]]>
</script>
EOT;
Wrap your string in <<<'EOT' EOT;
Upvotes: 4