CodeIgniter中替换字符串后执行PHP表单函数的问题
CodeIgniter中字符串替换后PHP代码无法执行的问题
现有代码与场景
- form.php 表单代码
<form method="post" action="result.php"> <input type="text" name="yourtext"> <input type="submit"> </form>
- 示例提交文本
my name is bagu and i live under a rock thanks
- result.php 处理代码
<?php $mytext = $_POST['yourtext']; $find = ["my name is","and i live", "thanks"]; $replace = ["<?php open_form('Form/insert') ?><input name='name' type='text' value='","'><br><input name='address' type='text' value='","'><input type='submit'><?php form_close() ?>"]; $intoform = str_replace($find, $replace, $mytext); echo $intoform; ?>
问题描述
目前已实现将提交文本中的"bagu"和"under a rock"分别填入对应文本框,但echo输出的open_form()、form_close()这类PHP代码无法被执行,此需求基于CodeIgniter框架。
补充信息
- 直接编写目标代码(不通过变量拼接+echo输出)时,代码可正常运行,示例代码如下:
<?php open_form('Form/insert') ?> <input name='name' type='text' value='bagu'><br> <input name='address' type='text' value='under a rock'> <input type='submit'> <?php form_close() ?>
- 扩展需求:当提交包含多组内容的文本时,需要生成对应数量的表单,例如提交3组内容则生成3个表单。
内容的提问来源于stack exchange,提问作者loveearthmix
相关产品推荐
相关产品推荐

