pk-fr / yakpro-po

YAK Pro - Php Obfuscator
http://www.php-obfuscator.com
Other
1.29k stars 363 forks source link

Does not play well with html template #1

Closed changwuf31 closed 9 years ago

changwuf31 commented 9 years ago

Particularlarly html template with inline php code inside

pk-fr commented 9 years ago

Updated README.md with:

Note: This tool has been written to obfuscate pure php sources.
it is not intended to be used with html and embeded php inside.

pk-fr commented 9 years ago

You can still embed html within php using the echo <<<END ... END; syntax!

changwuf31 commented 9 years ago

Ah.. Thanks for the tip :+1:

Ten0 commented 6 years ago

Hello, I would like to know if you have any suggestion as to how we could hence convert these mixed html/php files to pure php files (I mean, not manually) before putting them through your tool, since many of the things we may want to obfuscate, as users of this tool, contains mixed html and php. I couldn't find any tool that does this, they all convert pure html to php. NB: Converting pure html blocks to php should be pretty easy using a small set of regexes.

EDIT: I ended up writing my own code for this, feel free to integrate it :)

$c = preg_replace_callback('/\?>(.*)<\?php/sU', function ($match) {
    return '; echo \''.str_replace(array('\\', "'", "\n"), array('\\\\', "\\'", '\'."\\n".\''), $match[1]).'\';';
}, '<?php ?>'.$c.'<?php ?>');

(Note that as an alternate version where you don't need to preserve line breaks within the generated html source code you could use a single space ' ' instead of '\'."\\n".\'', which would also result in a smaller final file, additionally getting rid of the .'' and ''. kind of stuff.)