如何将 php 代码从 javascript 传输到 PHP? [英] How to transfer php code from javascript to PHP?

查看:37
本文介绍了如何将 php 代码从 javascript 传输到 PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

有没有其他方法可以将 PHP 代码从 javascipt 传输到 PHP?或者任何其他方式来执行 PHP 代码?我知道有一个 AJAX,但我想传输更大的数据,包括在 PHP 中出现的特殊字符(、'、]、[、$ 等).

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.

推荐答案

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

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.

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

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

这篇关于如何将 php 代码从 javascript 传输到 PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆