drgwsx8405 2015-01-01 18:13
浏览 47
已采纳

textarea不读取PHP代码[关闭]

Lately, I have been fond of live code editors such as cssdeck and jsFiddle, and I want to replicate my own with one small twist: php code.

The basic elements behind these live code editors are textarea, javascript, and an iframe. You can see the final results either via js script or php form. I went through the js script route, and it works fine for html, css, and js, but not php; the site shows up empty like nothing been entered. When I went the php form route, I got the same results. with php forms, however, I have the ability to create/write php files, which would then display the code correctly, but that would remove the live editing function. I'm wondering if you know any other routes to finish the intended project besides the ones above. Also, I tried

<?php
$codeInput = stripslashes($_POST['code']);
?>

and that turned nothing.

  • 写回答

1条回答 默认 最新

  • doubiao1734 2015-01-01 18:31
    关注

    You want to use htmlspecialchars, not stripslashes.

    htmlspecialchars is specifically for encoding things like <, as in <?php.

    stripslashes only removes backslashes (\).

    Be very careful with this, however; directly outputting unfiltered user input can lead to XSS attacks, even if you use htmlspecialchars. Read more here.

    As an aside, you probably don't need to roll your own editor for this. You might check out http://ideone.com/ instead, which is basically a jsFiddle for PHP and a large number of other languages.

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

报告相同问题?

悬赏问题

  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化