douhan9619 2016-02-09 19:45
浏览 30
已采纳

使用字符串中的信息替换PHP中的字符串

My current customer is aiming for a closed text-viewer, while keeping certain variables open for customers. This is to show a preview of the text, while not relying on the client side for the whole text. At the moment, I think of a form, which contains input elements. These elements will dynamically be filled into certain spans in the text so the client is able to see the preview. When the form is submitted, the server side will replace the identifiers with the inputs.

My current idea is to let my client create a text which contains identifiers, which the client can fill in or show with checkboxes. All these elements are stored in a mysql database, which can result in something like this:

You are thinking about %el1%, and you want to create %el2%. %bl3%

This is using the following inputs.

<input type="text" name="el1">
<input type="text" name="el2">
<input type="checkbox" name="bl3">

To replace these identifiers with A) elements which can be changed by Javascript and B) can be replaced by PHP in the full document.

You are thinking about <span id="el1"></span>, and you want to create <span id="el2"></span>. <span id="bl3" style="display:none;">This is a text that is retrieved from the database, and shown when the user checks the checkbox</span>

I don't know if this is a good idea at all, but the client wishes it to be this way. In this way, the client can't edit the full text, but only input certain inputs. I will validate these both client- and serverside.

Is this a good idea? If no, what should I do instead? And if yes, how can I create a loop that will find these identifiers based on %el1% or %bl3% and replace these with <span> tags or the submitted variables?

  • 写回答

2条回答 默认 最新

  • dqx76962 2016-02-09 19:55
    关注
    $phrase  = "You are thinking about %el1%, and you want to create %el2%. %bl3%.";
    $healthy = array("%el1%", "%el2%", "%bl3%");
    $yummy   = array("el1", "el2", "bl3");
    $newphrase = str_replace($healthy, $yummy, $phrase);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?