简体   繁体   English

在PHP中包含服务器端JavaScript

[英]Include server-side javascript in PHP

i'm converting in PHP5 a quite old ASP project that was using a lot of server-side javascript. 我正在PHP5中转换一个相当老的ASP项目,该项目使用了大量服务器端JavaScript。

is there a way to use that code or i'll have to rewrite everything in PHP? 有没有办法使用该代码,否则我将不得不重写PHP中的所有内容?

EDIT 编辑
this is how the code is embedded in ASP 这就是将代码嵌入ASP中的方式
<!-- #include file=helper.js -->

snippet of my helper.js 我的helper.js的片段
<script language=javascript runat=server>
//here are the functions
</script>

then in ASP is see that functions are called as usual ie 然后在ASP中看到函数被照常调用,即
response.write myJsfunction()

btw, if i have to rewrite the code, i'll do on my own, not using any software 顺便说一句,如果我不得不重写代码,我会自己做,不使用任何软件

The answer is "you need to rewrite everything in PHP" PHP does not as is support Javascript on the server-side in reuseable manner. 答案是“您需要用PHP重写所有内容” PHP不像服务器端以可重用的方式支持Javascript那样。 Also, the automatic code transformations are very klunky: clean up work takes more time than building everything by hand from the beginning. 而且,自动代码转换非常笨拙:清理工作比从一开始就手工构建所有工作要花费更多的时间。

However, you can run server-side Javascript code with tools like node.js and backbone.js. 但是,您可以使用诸如node.js和bone.js之类的工具运行服务器端Javascript代码。 Mixing with PHP code is no-go though as these projects will provide their own, non-PHP-compatible, web-servers. 不能混用PHP代码,因为这些项目将提供它们自己的,非PHP兼容的Web服务器。

I presume you mean jscript? 我想你是说jscript? Have you tried asp2php ? 您尝试过asp2php吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM