douqiao1983 2012-07-19 04:22
浏览 30
已采纳

PHP函数争夺javascript代码? [重复]

Possible Duplicate:
How can I obfuscate JavaScript?

I was wondering if there's a way to just move javascript around. So let's say I have a javascript file. I like to be able to have the PHP function just move the JS functions, etc around so it's less readable.

  1. Set path to javascript file
  2. Read the JS file
  3. Grab each JS function or jquery selector and move them around and save the file. The hard part is figuring how how to make sure each block of code is complete... hmm... maybe use 2 returns as a separator? Another idea is make each JS block a single sentence and just use PHP line shuffle?

Curious if this is do-able...

Thanks

UPDATE: What do you guys think of this? Using /// between each function and converting everything into array and then I'll randomize array and output it back out again

<?php
$file_content = file_get_contents("js/js.js");
$content = explode("///", $file_content);
echo count($content);
print_r($content);
?>
  • 写回答

1条回答 默认 最新

  • doubeng3216 2012-07-19 04:25
    关注

    Via PHP not sure but you can adapt UglifyJS. It has really good AST parsing, so you should probably read more on AST (abstract syntax tree) which is basically an outline of javascript code.

    Definitely doable.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R运行没有名称为"species"的插槽对于此对象类"SDMmodelCV"
  • ¥20 基于决策树的数字信号处理,2ask 2psk 2fsk的代码,检查下报错的原因
  • ¥20 python作业求过程
  • ¥15 wincc已组态的变量过多
  • ¥60 如图:直线与椭圆X轴平行,求直线与椭圆任意一点的相切坐标计算公式
  • ¥50 如何用python使用opencv里的cv::cudacodec::VideoWriter函数对视频进行GPU硬编码
  • ¥100 c#solidworks 二次开发 工程图自动标边线法兰 等折弯尺寸怎么标
  • ¥15 halcon DrawRegion 提示错误
  • ¥15 FastAPI Uvicorn启动显示404
  • ¥15 centos7.9脚本,怎么排除特定的访问记录