Tome String Completamente Literalmente en PHP

I generated an obfuscated email using the Hive Logic Enkoder. I want to echo the result in PHP.

The problem is that it contains ', ", \\ y \\\\, 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?

Así que quiero:

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

preguntado el 31 de julio de 12 a las 15:07

Show how you're reading this string. PHP won't do anything with metachars embedded in a string unless you're running that text somehow, e.g. via eval(). -

Parece que lo que quieres es Nowdocs. -

The syntax error is because your ending EOT; debe: be at the beginning of its line (i.e.: no whitespace before it and nothing after it). -

4 Respuestas

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;

Respondido 31 Jul 12, 15:07

Tenga en cuenta que Nowdoc support was added in PHP 5.3.0.. - igual

Ah yes, I got confused as I noticed this a while ago. Was thinking of heredoc - JConstantino

Doesn't it escape a double backslash, as it happens in single-quoted strings? - Lumbendil

@Lumbendil According to the manual, "no parsing is done inside nowdocs". I would assume that to include double backslashes. - paladio

If that's so, you're right, didn't check it... believed that since they where something like a multiline single-quoted string, they'd behave the same way. - Lumbendil

Intenta usar 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;

Respondido 31 Jul 12, 15:07

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 \\.

Respondido 31 Jul 12, 15:07

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.

Respondido 12 Abr '13, 19:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.