Mod xml curl PHP example

From FreeSWITCH Wiki
Jump to: navigation, search

Quick N Dirty PHP example

-This code should output a small sample config which can be used to call the FreeSwitch conference (More to be added later)

header('Content-Type: text/xml');
$xmlw = new XMLWriter();
$xmlw -> openMemory();
$xmlw -> setIndent(true);
$xmlw -> setIndentString('  ');
$xmlw -> startDocument('1.0', 'UTF-8', 'no');

$xmlw -> startElement('document');
$xmlw -> writeAttribute('type', 'freeswitch/xml');

$xmlw -> startElement('section');
$xmlw -> writeAttribute('name', 'dialplan');
$xmlw -> writeAttribute('description', 'RE Dial Plan For FreeSwitch');

//start the context
$xmlw -> startElement('context');
$xmlw -> writeAttribute('name', 'default');

//start an extension
$xmlw -> startElement('extension');
$xmlw -> writeAttribute('name', 'test9');

//write the condition to match on
$xmlw -> startElement('condition');
$xmlw -> writeAttribute('field', 'destination_number');
$xmlw -> writeAttribute('expression', '^83789$');

//set the action/anti-action to take
$xmlw -> startElement('action');
$xmlw -> writeAttribute('application', 'bridge');
$xmlw -> writeAttribute('data', 'iax/');

$xmlw -> endElement();
$xmlw -> endElement();
// </extension>
$xmlw -> endElement();
// </context>
$xmlw -> endElement();
$xmlw -> endElement();
$xmlw -> endElement();
echo $xmlw -> outputMemory();

Alternate example

- requires no xml library


header('Content-Type: text/xml');

$response = <<< XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="freeswitch/xml">
  <section name="dialplan" description="example_curl_dialplan">
    <context name="default">
      <extension name="curl_test">
        <condition field="destination_number" expression="^83789$">
          <action application="bridge" data="iax/"/>



See Also: mod_xml_curl