Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echoing PHP Variable inside XML [duplicate]

Tags:

php

curl

xml

I'm collecting form information and I have to post that data to a URL in XML format. So I'm putting the XML into a post string and using cURL to execute the post. How would I echo the proper form fields into the XML? In the ProjectId I put what I thought would be the code, but Notepad++ isn't showing it as being valid PHP so I think that's wrong. Thanks!

$post_string = '

<?xml version="1.0" encoding="UTF-8" ?>

<Ping vid="" sid="">                   
   <ProjectInfo>
      <ProjectId><? echo $projectid; ?></ProjectId>
      <SubProject></SubProject>
   </ProjectInfo>
 </Ping>


 ';

I was using this link to figure it out: http://www.codediesel.com/php/posting-xml-from-php/

like image 936
Paul Avatar asked Sep 12 '26 20:09

Paul


2 Answers

Just concatenate the string

$post_string = '

<?xml version="1.0" encoding="UTF-8" ?>

<Ping vid="" sid="">                   
   <ProjectInfo>
      <ProjectId>' . $projectid . '</ProjectId>
      <SubProject></SubProject>
   </ProjectInfo>
 </Ping>


 ';
like image 79
AlienWebguy Avatar answered Sep 15 '26 09:09

AlienWebguy


Just another style of usage. Try this style for giving a well formatted xml string to a php variable.

$post_string =<<<XML
<Ping vid="" sid="">                   
<ProjectInfo>
  <ProjectId>$projectid</ProjectId>
  <SubProject></SubProject>
</ProjectInfo>
</Ping>
XML;
like image 30
Matricore Avatar answered Sep 15 '26 09:09

Matricore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!