Skip to main content

mod_xml_curl PHP example

About

mod_xml_curl examples written in PHP programming language.

Click here to expand Table of Contents

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)

<?php
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/guest@conference.freeswitch.org/888');

//</action>
$xmlw -> endElement();
//</condition>
$xmlw -> endElement();
// </extension>
$xmlw -> endElement();
// </context>
$xmlw -> endElement();
//</section>
$xmlw -> endElement();
//</document>
$xmlw -> endElement();
echo $xmlw -> outputMemory();
?>

Alternate example

Requires no xml library

<?php

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/guest@conference.freeswitch.org/888"/>
</condition>
</extension>
</context>
</section>
</document>
XML;

die($response);

?>

See Also: mod_xml_curl