I can help:
I've adapt an example from
http://de2.php.net/manual/de/ref.xml.php
and think it's suitable.
Requirements:
You need an php-modul (xml-support), what you can check with phpinfo()
(im my case:
XML Support active
XML Namespace Support active
EXPAT Version expat_1.95.5
)
and in the system built-in the expat-library (look url on top)
Code: Select all
<?php
/** -------------------------------------------------------------------------\n
* @file adsl_ch.class.php
* @class ClADSLCheck adsl_ch.class.php
* @desc Swisscom Switzerland ADSL Checker\n
* --------------------------------------------------------------------------\n
* PHP4Class: ClADSLCheck\n
* - liefert die Details zur ADSL Moeglichkeit eines Anschlusses\n
* im Gebiet von Swisscom Switzerland
* - gently translated in a class
* - should be placed in the {p}-frontend_init-Folder:
* phpwcms_template/inc_script/frontend_init/
* - with example call in the tail-end
* --------------------------------------------------------------------------\n
* @version 0.2 $Rev. 2005-05-31 $
* @author Neelix <http://www.phpwcms.de/forum/privmsg.php?mode=post&u=1672>
* @package phpwcms
* @subpackage adsl_ch
* @licence GPL(2)
*
* @see Forum 4 Details [http://www.phpwcms.de/forum/viewtopic.php?t=6995]
* @see xml background http://de2.php.net && [andrewcare at execulink dot com] http://de2.php.net/manual/de/ref.xml.php
* @see http://de3.php.net/manual/de/function.xml-set-object.php
*
* @TODO waiting4wishes++
* ---------------------------------------------------------------------------
*/
class ClADSLCheck
{
var $depth;
var $offset;
var $elements;
var $stack;
var $count;
var $depth;
var $cons;
var $summary;
var $xml_parser;
/**
* Konstruktor
*
* Init the Members + call the parser
* @param String $file URI will return the XML-File <SL_CHECK_RESULT>...</SL_CHECK_RESULT>
* - example from ssyfrig: http://www.swisscom.com/ws/e-tools/adsl/LineCheck?tn=0444627060&lang=de&Product=bbcs&RequestedBC=06
*/
function ClADSLCheck($file)
{
$this->count = 0;
$this->depth = 0;
$this->offset = 0;
$this->cons = array();
$this->summary = 0;
$this->elements = array();
$this->stack = array();
$this->xml_parser = xml_parser_create();
xml_set_object($this->xml_parser, $this); //see http://de3.php.net/manual/de/function.xml-set-object.php
xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, 0); //case sEnSiTiVe please!
xml_set_element_handler($this->xml_parser, '_start_handler', '_end_handler');
xml_set_character_data_handler($this->xml_parser, "_data_handler");
if(!($handle = @fopen($file, "r")))
die('ADSLCheck Error: XMLParser cannot open "'.$file.'"');
while($contents = @fread($handle, 4096))
{
xml_parse($this->xml_parser, $contents, feof($handle));
}
@fclose($handle);
xml_parser_free($this->xml_parser);
} //end-fnc
/**
* CallBack 4 Parser: StartTag
*
* @access private
*
* @param Resource $parser parserhandle
* @param String $name elementname
* @param Array $attribs all propertys
*
* @see http://de2.php.net/manual/de/function.xml-set-object.php
* @see http://de2.php.net/xml_set_element_handler
*/
function _start_handler($parser, $name, $attribs)
{
$this->elements[$this->count] = array();
$this->elements[$this->count]['name'] = $name;
while(list($key, $value) = each($attribs))
{
$this->elements[$this->count]['attributes'][$key] = $value;
}
$this->elements[$this->count]['depth'] = $this->depth;
array_push($this->stack, $this->count);
$this->count++;
$this->depth++;
}//end-fnc
/**
* CallBack 4 Parser: EndTag
*
* @access private
*
* @param Resource $parser parserhandle
* @param String $name elementname
*
* @see http://de2.php.net/manual/de/function.xml-set-object.php
* @see http://de2.php.net/xml_set_element_handler
*/
function _end_handler($parser, $name)
{
array_pop($this->stack);
$this->depth--;
}//end-fnc
/**
* CallBack 4 Parser: Data
*
* @access private
*
* @param Resource $parser parserhandle
* @param String $data elementdatas
*
* @see http://de2.php.net/manual/de/function.xml-set-object.php
* @see http://de2.php.net/xml_set_element_handler
*/
function _data_handler($parser, $data)
{
$this->elements[$this->stack[count($this->stack)-1]]['data'] .= trim($data);
}//end-fnc
/**
* Working through the xml-tree
* - if we can find the OK-Message -> collect all infos in the internal buffer
* - killed all output from andrewcare - only the info messages will be saved
*
* @access public
* @return Boolean will be true, if the telnumber is ready
*
*/
function worker()
{
while( list($key_a) = each($this->elements))
{
$this->depth--;
$this->offset = 0;
if ( $this->elements[$key_a]['depth'] < $this->depth )
{
while($this->elements[$key_a]['depth'] != (($this->elements[$key_a - $this->offset]['depth']) - 1) || $this->offset == 0)
{
$this->offset++;
}
$this->depth--;
}
if ($this->elements[$key_a]['depth']==$this->depth && ($this->depth != 0) )
{
while($this->elements[$key_a]['depth'] != $this->elements[$key_a - $this->offset]['depth'] || $this->offset == 0)
{
$this->offset++;
}
$this->depth--;
}
$this->depth++;
if (!empty($this->elements[$key_a]['attributes']))
{
while(list($key_b, $value) = each($this->elements[$key_a]['attributes']))
{
if ($key_b=='Code' && $value=='OK') // <MESSAGE Code="OK">
{
$this->summary=1;
}
}
}
//collect the details
if (trim($this->elements[$key_a]['data']) != '' && $this->summary==1)
$this->cons[]=$this->elements[$key_a]['data'];
$this->depth++;
}//w-end
return $this->summary; //it's integer but using as boolean
}//end-fnc
}; //End-CLASS
/* <------------------------------[cut here]----------------------------------------> */
/*
* --<Example call: copy this in your formular or content and try>---------------------------------------------------
* @file adsl_ch.example.php
*/
//the file adsl_ch.class.php should be placed here!
//delete the "//" after testing in the next line
//include_once(PHPWCMS_ROOT.'/phpwcms_template/inc_script/frontend_init/adsl_ch.class.php');
if (isset($_GET['Submit']))
{
echo 'Ergebnis:<br><hr>';
//OK-Example: tn=0444627060
$myADSL= new ClADSLCheck('http://www.swisscom.com/ws/e-tools/adsl/LineCheck?tn='.$_GET['tn'].'&lang=de&Product=bbcs&RequestedBC='.$_GET['requestedbc']);
if ($myADSL->worker())
{
//status quo 2005-05-26:
//1st Line ($i==0) is the OK Message: "Der Telefonanschluss ist für ADSL geeignet. Folgende Datenübertragungsraten sind möglich:"
//then the details...
for ($i=0;$i<count($myADSL->cons);$i++)
{
echo $myADSL->cons[$i].'<br>';
}
}
else
echo 'Es handelt sich um einen Telefonanschluss der für ADSL leider nicht geeignet ist<br>';
echo '<hr>';
}//end-if-submit
?>
<form name="form1" method="get" action="adsl_ch.example.php">
The default is an example for an valid value!<br>
<input name="tn" type="text" class="style1" id="tn" value="<?php echo (isset($_GET['tn'])?$_GET['tn']:'0444627060'); ?>">
<br>
<input type="radio" name="requestedbc" value="06" <?php echo (!isset($_GET['requestedbc']) || $_GET['requestedbc']!='01'?'checked':''); ?>> ISDN<br>
<input type="radio" name="requestedbc" value="01" <?php echo (isset($_GET['requestedbc']) && $_GET['requestedbc']=='01'?'checked':''); ?>> ANALOG<br>
<input type="submit" name="Submit" value="Submit">
<!--
{Nx} It's now static in code connected!
<input type="hidden" name="lang" value="de">
<input name="Product" type="hidden" id="Product" value="bbcs">
//-->
</form>
Erfahrung ist das, was man besitzt, kurz nach dem es gebraucht wurde.
Warning: I have no foggiest idea of English/German, but I do
-ha{p}{p}y day/night/dia/noche-