Javascript 如何更改用户的html表单输入并在evrey';

Javascript 如何更改用户的html表单输入并在evrey';,javascript,php,python,html,textarea,Javascript,Php,Python,Html,Textarea,这似乎很复杂 我有一个html表单,允许用户上传python代码。提交时,python代码位于全新页面上的文本区域中,例如: <textarea id='yourcode' cols='40' rows='10'> <?php echo 'inch = 1 centimeter = 2.54 inch1 = float(raw_input('Enter the value in inches that you want to convert. ')) print "A

这似乎很复杂

我有一个html表单,允许用户上传python代码。提交时,python代码位于全新页面上的文本区域中,例如:

<textarea id='yourcode' cols='40' rows='10'>
<?php echo 'inch = 1 
centimeter = 2.54 
inch1 = float(raw_input('Enter the value in inches 
that you want to convert. ')) 
print "A value of %r inches is equal to %r centimeters." 
% (inch1,inch1 * inch * centimeter) '; ?>
</textarea>

如您所见,python“与php交互”并导致错误。是否自动读取insert并添加\以便python中的“”不会交互。它会将上面的代码(不起作用)更改为



以上这些都会起作用。抱歉,如果这是完整的,并询问您是否有问题。是否有人知道如何创建此脚本,自动在用户输入的python代码前面添加一个\n,该代码可能包含一个“破坏脚本的”字符。谢谢

如果您在PHP代码中嵌入了Python代码,请在PHP中使用:

addslashes($thePythonTextYouWantToAdd\)

更简单的是,没有中间变量:

<textarea id='yourcode' cols='40' rows='10'>
<?php echo <<<EOT
    inch = 1
    centimeter = 2.54
    inch1 = float(raw_input('Enter the value in inches
      that you want to convert. '))
    print "A value of %r inches is equal to %r centimeters."
      % (inch1,inch1 * inch * centimeter)
EOT; ?>
</textarea>

更安全的版本,用于防止有害的HTML代码:

<textarea id='yourcode' cols='40' rows='10'>
<?php echo filter_var( <<<EOT
    inch = 1
    centimeter = 2.54
    inch1 = float(raw_input('Enter the value in inches
      that you want to convert. '))
    print "A value of %r inches is equal to %r centimeters."
      % (inch1,inch1 * inch * centimeter)
EOT
    , FILTER_SANITIZE_FULL_SPECIAL_CHARS ?>
</textarea>


python在PHP中是怎样的?它不应该是一个变量吗?如果是php echo vairableuse
addslashes
,则解释python代码的javascript不起作用。我不确定如何做请解释你的答案。其他人会投反对票的。你好。用户可以将任何python代码上传到我的网站,它会编写一个带有该代码的新页面,然后我有一个javascript python intrpeter在网站上运行该代码。请问您为什么这样做?有各种各样的方法来实现你想要的,所以我假设你已经绕过了这个问题,找到了最适合你的方法。只是好奇。您好,我正在制作的网站在这里:代码部分是插入代码的地方。如果您添加一些代码,只需但是,如果您插入一些带有“it throws a error”的python代码,您当然必须管理不稳定的输入,以防止PHP代码抛出异常。heredoc免除了转义字符串的负担,但不能保证它是有效的输入。您还需要检查它,特别是考虑到它可能包含潜在有害的
标记。
<textarea id='yourcode' cols='40' rows='10'>
<?php echo <<<EOT
    inch = 1
    centimeter = 2.54
    inch1 = float(raw_input('Enter the value in inches
      that you want to convert. '))
    print "A value of %r inches is equal to %r centimeters."
      % (inch1,inch1 * inch * centimeter)
EOT; ?>
</textarea>
<textarea id='yourcode' cols='40' rows='10'>
<?php echo filter_var( <<<EOT
    inch = 1
    centimeter = 2.54
    inch1 = float(raw_input('Enter the value in inches
      that you want to convert. '))
    print "A value of %r inches is equal to %r centimeters."
      % (inch1,inch1 * inch * centimeter)
EOT
    , FILTER_SANITIZE_FULL_SPECIAL_CHARS ?>
</textarea>