简体   繁体   English

修改PHP变量内的内容

[英]Modifying content inside a PHP variable

I have this: 我有这个:

$data = '<tag>content</tag>';

And I'd like to know if it's possible to modify the content inside the tags as shown, and how. 而且我想知道是否有可能如图所示修改标签内的内容,以及如何进行修改。

For example, if the user inputs "car", then the variable should be: 例如,如果用户输入“ car”,则变量应为:

$data = '<tag>car</tag>';

This is for the purpose of inserting user input from an HTML form into the variable. 这是为了将来自HTML表单的用户输入插入变量中。 The variable itself is supposed to contain an XML structure. 该变量本身应该包含XML结构。

if I understand your question correctly you want to get the user's input and save it to the variable $data 如果我正确理解了您的问题,则希望获取用户的输入并将其保存到变量$ data中

try this (if your using POST method) 试试看(如果您使用POST方法)

$HTMLdata = $_POST['inputfieldname'];
$data = "<tag>".$HTMLdata."</tag>";

I hope I helped you 希望对你有帮助

为什么不只是在用户输入周围连接标签?

$data = '<tag>'.$_POST['input'].'</tag>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM