-1

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:

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

This is for the purpose of inserting user input from an HTML form into the variable. The variable itself is supposed to contain an XML structure.

  • 1
    `$data = 'something else';`? It's unclear exactly what you're asking – Phil Mar 05 '19 at 05:31
  • `This is for the purpose of inserting user input from an HTML form into the variable. The variable itself is supposed to contain an XML structure.` That's pretty much it, without going to deep into it. For more detail, I'm trying to send the variable elsewhere as XML through PHP curl. –  Mar 05 '19 at 05:39
  • Possible duplicate of [How Do You Parse and Process HTML/XML in PHP?](https://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – Phil Mar 05 '19 at 05:41
  • show us your xml data – sumit Mar 05 '19 at 05:53

2 Answers2

2

if I understand your question correctly you want to get the user's input and save it to the variable $data

try this (if your using POST method)

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

I hope I helped you

Phil
  • 157,677
  • 23
  • 242
  • 245
  • Almost. I want to insert user input in between the XML tags that are inside the variable. `$data = 'replace_this_with_user_input';`, something like that. I edited the original post to better explain it. –  Mar 05 '19 at 05:46
  • you want to change the value of the $data once the user change the value of the inputfield in the HTML without clicking a button? – Jerick Arcega Mar 05 '19 at 05:53
  • You're not wrong, I misunderstood your answer which is completely valid. Thanks! –  Mar 05 '19 at 05:55
1

Why not just concatenate the tags around the user input?

$data = '<tag>'.$_POST['input'].'</tag>';
iamianjb
  • 9
  • 4