如何将 php 代码从 javascript 转移到 PHP?

发布于 2024-11-28 21:05:34 字数 301 浏览 3 评论 0原文

所以我创建文本(php)编辑器,我想执行 PHP 代码而不刷新页面。 现在我使用 cookie 从 javascript 传输代码(抓取编辑器内容)。 然后颜色框打开,PHP 文件将 cookie 内容写入文件,该文件已包含在内。 还有一个问题:

是否有其他方法可以将 PHP 代码从 javascipt 转移到 PHP?或者还有其他方法来执行 PHP 代码吗?我知道有一个 AJAX,但我想传输更大的数据,包括 PHP 中出现的特殊字符(“、”、]、[、$ 等)。

是的,我仅在本地主机上使用它,仅用于教育目的: ) 抱歉我的英语不好,希望你能理解我。

So I create text(php) editor and I want to execute PHP code without refreshing page.
Now I use cookies to transfer code from javascript(which grab editor content).
Then color box opens and PHP file write cookie content to file, which is included.
And there is question:

Is there any other way to transfer PHP code from javascipt to PHP? Or any other way to execute PHP code? I know there is a AJAX, but I want to transfer a larger data including special characters(",',],[,$ etc.), that occur in PHP.

Yes, I use it only on localhost for education purpose only :)
Sorry for my english, I hope you understand me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

各空 2024-12-05 21:05:34

AJAX适合发送大量代码。看一下 jQuery.postjQuery.ajax。特殊字符通过 POST 请求不变。

确保将 php 设置 magic_quotes_gpc 设置为 off,因为此选项告诉 PHP 使用反斜杠转义任何特殊字符。

AJAX is suitable for sending large amounts of code. Take a look at jQuery.post and jQuery.ajax. Special characters pass through POST-request unchanged.

Make sure you set php setting magic_quotes_gpc to off, as this option tells PHP to escape any special character with backslash.

触ぅ动初心 2024-12-05 21:05:34

这次您仍然可以使用 AJAX,只是使用 POST。
尝试如下操作:

<script>
code = '<? echo "Hi"; ?>'
ajax = new XMLHttpRequest();
ajax.open("POST","http://foo.com/bar.php";
ajax.send("code="+code+"&foo=bar")
</script>

查看 https://developer.mozilla.org/en/ajax 来学习有关阿贾克斯的更多信息。

You can still use AJAX, only with POST, this time.
Try something like:

<script>
code = '<? echo "Hi"; ?>'
ajax = new XMLHttpRequest();
ajax.open("POST","http://foo.com/bar.php";
ajax.send("code="+code+"&foo=bar")
</script>

Look at https://developer.mozilla.org/en/ajax to learn more about Ajax.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文