You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CodeIgniter中替换字符串后执行PHP表单函数的问题

CodeIgniter中字符串替换后PHP代码无法执行的问题

现有代码与场景

  1. form.php 表单代码
<form method="post" action="result.php">
<input type="text" name="yourtext">
<input type="submit">
</form>
  1. 示例提交文本
my name is bagu and i live under a rock thanks
  1. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 09:12:26