Jump to content

XML code value into a string for PHP


tylercaiden

Recommended Posts

This is an SMS app i have started building yesterday. I really don't know much about CGI and XML but I am pretty decent with PHP.

 

I am just testing on one of my servers but plan to use this with my MSSQL appointment database for techs to get their service calls.

 

My server will read PHP in a XML document and this is really a PHP file but the required file name is just sent to a PHP doc from mod_rewrite.

 

<?xml version="1.0" encoding="UTF-8" ?> 
<cmrl xmlns:dotgo="http://dotgo.com/cmrl/1.0"> 
  <match pattern="*"> 
  <message> 
    <content>Reply with your user name</content> 
    <input name="name"> 
      <message> 
        <content><?php 
header('Content-Type: text/xml'); 

$string = <<<XML 
<get name="name"/> 
XML; 

$xml = simplexml_load_string($string); 

var_dump($xml); 

$conn = mysql_connect("localhost", "x", "x"); 

$db = mysql_select_db("db"); 

$queryl  = "SELECT * FROM user where user = '$xml'"; 
$resultl = mysql_query($queryl, $conn); 
while($row = mysql_fetch_array($resultl)) 
{ 
$myname = $row['name']; 
echo $myname; 
} 
?>Thanks <get name="name"/> 
        </content> 
      </message> 
    </input> 
  </message> 
</match> 
  </cmrl> 

 

This is one of the attempts I have made to get this working. The tech sends a message with their user name and it returns data from MySQL. <get name="name"/> is the user name and it does return a text message with "Thanks name".

 

I just need the PHP to be able to get the data from <get name="name"/> in the same document.

 

http://dotgo.com is the only place I know of using this CMRL coding. I check their documentation for it but they show examples using CGI and XML alone.

Link to comment
https://forums.phpfreaks.com/topic/128070-xml-code-value-into-a-string-for-php/
Share on other sites

NO NO NO...

This is not how you do it :)

 

Its simple... Here how you write content from php in an xml file

<?php
// write code / logic to get content
$content="some content here";


$xml = '<?xml version="1.0" encoding="UTF-8" ?>
<cmrl xmlns:dotgo="http://dotgo.com/cmrl/1.0">
  <match pattern="*">
  <message>
    <content>Reply with your user name</content>
    <input name="name">
      <message>
        <content>'.$content.'</content>
      </message>
    </input>
  </message>
</match>
  </cmrl>';


// now this is how to display all this page as an XML file:
header("Content-type: text/xml");
echo $xml;
?>

Hi,

 

What you're looking for is the CMRL <engine> tag.  Here's how to use it:

 

In your index.cmrl file, put:

 

<?xml version="1.0" encoding="UTF-8" ?> 
<cmrl xmlns:dotgo="http://dotgo.com/cmrl/1.0"> 
  <match pattern="*"> 
  <message> 
    <content>Reply with your user name</content> 
    <input name="name"> 
      <engine href="http://yourdomain/dotgo.php" />
    </input>
  </message>
  </match>
</cmrl>

 

This means that after the user replies to the <input>, the result of the input will be POSTed as the value of the variable "name" to the URL at "http://yourdomain/dotgo.php" (along with a bunch of other variables having to do with the text message).  That URL just has to return any "terminating node", e.g. <message>, <block>, <engine>, etc., which will be sent to the user.

 

So now create a PHP script at http://yourdomain/dotgo.php that contains something like the following:

 

<?php

  $name = $_REQUEST['name'];

  $message = <<<XML
  <block>
  <set name="user_name">$name</set>
<message><content>Welcome $name!</content></message>
  </block>
XML;

  print $message;
  
?>

 

This example also shows you how to store the $name variable into the user's session (using the <set> tag), so that the next time the same user sends any text message to your domain that results in an <engine>, you'll be able to retrieve the value from the $_REQUEST['user_name'] variable.

 

For more info check out the documents "How to Implement DOTGO Engines" and "Session variables in CMRL" at http://dotgo.com/support/documentation

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.