这似乎很复杂。你知道吗
我有一个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中的“”不会交互。它会将上面的代码(不起作用)更改为
<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代码前面添加一个“\n”来破坏脚本。谢谢
如果在PHP代码中嵌入了Python代码,请在PHP中使用heredoc:
更简单,没有中间变量:
使用filter_var()防止有害HTML代码的更安全版本:
遗传病不必逃脱。但是,存在一些安全问题。但真正的问题是:如何从表单中获取用户输入字符串?你知道吗
相关问题 更多 >
编程相关推荐