* @license http://opensource.org/licenses/bsd-license New BSD License
* @version CVS: $Id$
* @link http://pear.php.net/package/XML_Util
*/
/**
* set error level
*/
error_reporting(E_ALL);
require_once 'XML/Util.php';
/**
* replacing XML entities
*/
print 'replace XML entities:
';
print XML_Util::replaceEntities('This string contains < & >.');
print "\n
\n";
/**
* reversing XML entities
*/
print 'replace XML entities:
';
print XML_Util::reverseEntities('This string contains < & >.');
print "\n
\n";
/**
* building XML declaration
*/
print 'building XML declaration:
';
print htmlspecialchars(XML_Util::getXMLDeclaration());
print "\n
\n";
print 'building XML declaration with additional attributes:
';
print htmlspecialchars(XML_Util::getXMLDeclaration('1.0', 'UTF-8', true));
print "\n
\n";
/**
* building document type declaration
*/
print 'building DocType declaration:
';
print htmlspecialchars(XML_Util::getDocTypeDeclaration('package',
'http://pear.php.net/dtd/package-1.0'));
print "\n
\n";
print 'building DocType declaration with public ID (does not exist):
';
print htmlspecialchars(XML_Util::getDocTypeDeclaration('package',
array('uri' => 'http://pear.php.net/dtd/package-1.0',
'id' => '-//PHP//PEAR/DTD PACKAGE 0.1')));
print "\n
\n";
print 'building DocType declaration with internal DTD:
';
print '';
print htmlspecialchars(XML_Util::getDocTypeDeclaration('package',
'http://pear.php.net/dtd/package-1.0',
''));
print '
';
print "\n
\n";
/**
* creating an attribute string
*/
$att = array(
'foo' => 'bar',
'argh' => 'tomato'
);
print 'converting array to string:
';
print XML_Util::attributesToString($att);
print "\n
\n";
/**
* creating an attribute string with linebreaks
*/
$att = array(
'foo' => 'bar',
'argh' => 'tomato'
);
print 'converting array to string (including line breaks):
';
print '';
print XML_Util::attributesToString($att, true, true);
print '
';
print "\n
\n";
/**
* splitting a qualified tag name
*/
print 'splitting qualified tag name:
';
print '';
print_r(XML_Util::splitQualifiedName('xslt:stylesheet'));
print '
';
print "\n
\n";
/**
* splitting a qualified tag name (no namespace)
*/
print 'splitting qualified tag name (no namespace):
';
print '';
print_r(XML_Util::splitQualifiedName('foo'));
print '
';
print "\n
\n";
/**
* splitting a qualified tag name (no namespace, but default namespace specified)
*/
print 'splitting qualified tag name '
. '(no namespace, but default namespace specified):
';
print '';
print_r(XML_Util::splitQualifiedName('foo', 'bar'));
print '
';
print "\n
\n";
/**
* verifying XML names
*/
print 'verifying \'My private tag\':
';
print '';
print_r(XML_Util::isValidname('My Private Tag'));
print '
';
print "\n
\n";
print 'verifying \'-MyTag\':
';
print '';
print_r(XML_Util::isValidname('-MyTag'));
print '
';
print "\n
\n";
/**
* creating an XML tag
*/
$tag = array(
'namespace' => 'foo',
'localPart' => 'bar',
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'),
'content' => 'I\'m inside the tag'
);
print 'creating a tag with namespace and local part:
';
print htmlentities(XML_Util::createTagFromArray($tag));
print "\n
\n";
/**
* creating an XML tag
*/
$tag = array(
'qname' => 'foo:bar',
'namespaceUri' => 'http://foo.com',
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'),
'content' => 'I\'m inside the tag'
);
print 'creating a tag with qualified name and namespaceUri:
';
print htmlentities(XML_Util::createTagFromArray($tag));
print "\n
\n";
/**
* creating an XML tag
*/
$tag = array(
'qname' => 'bar',
'namespaceUri' => 'http://foo.com',
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable')
);
print 'creating an empty tag without namespace but namespace Uri:
';
print htmlentities(XML_Util::createTagFromArray($tag));
print "\n
\n";
/**
* creating an XML tag with more namespaces
*/
$tag = array(
'namespace' => 'foo',
'localPart' => 'bar',
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'),
'content' => 'I\'m inside the tag',
'namespaces' => array(
'bar' => 'http://bar.com',
'pear' => 'http://pear.php.net',
)
);
print 'creating an XML tag with more namespaces:
';
print htmlentities(XML_Util::createTagFromArray($tag));
print "\n
\n";
/**
* creating an XML tag with a CData Section
*/
$tag = array(
'qname' => 'foo',
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'),
'content' => 'I\'m inside the tag'
);
print 'creating a tag with CData section:
';
print htmlentities(XML_Util::createTagFromArray($tag, XML_UTIL_CDATA_SECTION));
print "\n
\n";
/**
* creating an XML tag with a CData Section
*/
$tag = array(
'qname' => 'foo',
'attributes' => array('key' => 'value', 'argh' => 'tt'),
'content' =>
'Also XHTML-tags can be created '
. 'and HTML entities can be replaced <>.'
);
print 'creating a tag with HTML entities:
';
print htmlentities(XML_Util::createTagFromArray($tag, XML_UTIL_ENTITIES_HTML));
print "\n
\n";
/**
* creating an XML tag with createTag
*/
print 'creating a tag with createTag:
';
print htmlentities(XML_Util::createTag('myNs:myTag',
array('foo' => 'bar'),
'This is inside the tag',
'http://www.w3c.org/myNs#'));
print "\n
\n";
/**
* trying to create an XML tag with an array as content
*/
$tag = array(
'qname' => 'bar',
'content' => array('foo' => 'bar')
);
print 'trying to create an XML tag with an array as content:
';
print '';
print_r(XML_Util::createTagFromArray($tag));
print '
';
print "\n
\n";
/**
* trying to create an XML tag without a name
*/
$tag = array(
'attributes' => array('foo' => 'bar'),
);
print 'trying to create an XML tag without a name:
';
print '';
print_r(XML_Util::createTagFromArray($tag));
print '
';
print "\n
\n";
?>
PK HqYقH
' HTTP_Request/docs/download-progress.phpnu [ HTTP_Request_Listener();
}
/**
* Opens the target file
* @param string Target file name
* @throws PEAR_Error
*/
function setTarget($target)
{
$this->_target = $target;
$this->_fp = @fopen($target, 'wb');
if (!$this->_fp) {
PEAR::raiseError("Cannot open '{$target}'");
}
}
function update(&$subject, $event, $data = null)
{
switch ($event) {
case 'sentRequest':
$this->_target = basename($subject->_url->path);
break;
case 'gotHeaders':
if (isset($data['content-disposition']) &&
preg_match('/filename="([^"]+)"/', $data['content-disposition'], $matches)) {
$this->setTarget(basename($matches[1]));
} else {
$this->setTarget($this->_target);
}
$this->_bar =& new Console_ProgressBar(
'* ' . $this->_target . ' %fraction% KB [%bar%] %percent%', '=>', '-',
79, (isset($data['content-length'])? round($data['content-length'] / 1024): 100)
);
$this->_size = 0;
break;
case 'tick':
$this->_size += strlen($data);
$this->_bar->update(round($this->_size / 1024));
fwrite($this->_fp, $data);
break;
case 'gotBody':
fclose($this->_fp);
break;
case 'connect':
case 'disconnect':
break;
default:
PEAR::raiseError("Unhandled event '{$event}'");
} // switch
}
}
// Try using any other package if you like, but choose the bigger ones
// to be able to see the progress bar
$url = 'http://pear.php.net/get/HTML_QuickForm-stable';
$req =& new HTTP_Request($url);
$download =& new HTTP_Request_DownloadListener();
$req->attach($download);
$req->sendRequest(false);
?>
PK HqY q q HTTP_Request/docs/example.phpnu [ |
// +-----------------------------------------------------------------------+
/**
* This will grab a webpage and display it
*
* @category HTTP
* @package HTTP_Request
* @version CVS: $Id: example.php,v 1.7 2007/05/18 19:20:12 avb Exp $
* @ignore
*/
/**
* Class for performing HTTP requests
*/
include('HTTP/Request.php');
$req = &new HTTP_Request('http://www.php.net');
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addPostData('Foo', 'bar');
$req->sendRequest();
$response1 = $req->getResponseBody();
$req->setMethod(HTTP_REQUEST_METHOD_GET);
$req->setURL('http://pear.php.net');
$req->clearPostData();
$req->sendRequest();
$response2 = $req->getResponseBody();
echo $response1;
echo $response2;
?>PK HqYg Net_URL/docs/6470.phpnu [ setOption('encode_query_keys', true);
print_r($url->querystring);
?>
PK HqYJ6
6
Net_URL/docs/example.phpnu [ |
// +-----------------------------------------------------------------------+
// $Id: example.php,v 1.12 2007/06/28 14:42:42 davidc Exp $
/**
* This example will decode the url given and display its
* constituent parts.
*/
//include('../URL.php');
include('Net/URL.php');
//$url = &new Net_URL('https://www.example.com/foo/bar/index.php?foo=bar');
$url = new Net_URL('https://example.com/pls/portal30/PORTAL30.wwpob_page.changetabs?p_back_url=http%3A%2F%2Fexample.com%2Fservlet%2Fpage%3F_pageid%3D360%2C366%2C368%2C382%26_dad%3Dportal30%26_schema%3DPORTAL30&foo=bar');
?>
Protocol...: protocol?>
Username...: user?>
Password...: pass?>
Server.....: host?>
Port.......: port?>
File/path..: path?>
Querystring: querystring)?>
Anchor.....: anchor?>
Full URL...: getUrl()?>
PK HqY^? ? Net_SMTP/examples/basic.phpnu [ connect())) {
die($e->getMessage() . "\n");
}
$smtp->auth('username','password');
/* Send the 'MAIL FROM:' SMTP command. */
if (PEAR::isError($smtp->mailFrom($from))) {
die("Unable to set sender to <$from>\n");
}
/* Address the message to each of the recipients. */
foreach ($rcpt as $to) {
if (PEAR::isError($res = $smtp->rcptTo($to))) {
die("Unable to add recipient <$to>: " . $res->getMessage() . "\n");
}
}
/* Set the body of the message. */
if (PEAR::isError($smtp->data($subj . "\r\n" . $body))) {
die("Unable to send data\n");
}
/* Disconnect from the SMTP server. */
$smtp->disconnect();
PK HqYO/&