Source for file Utility.php
Documentation is available at Utility.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* This source file is subject to version 2.1 of the GNU Lesser General Public
* License, that is bundled with this package in the file COPYING, available
* through the world wide web at the following URI:
* http://www.gnu.org/copyleft/lesser.html.
* @author Alessandro Rossini <http://www.alessandrorossini.org>
* @author Graziano Liberati <http://www.liberati.org>
* @copyright 2004-2007 The ZNF Development Team
* @license LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
* @version SVN $Id: Utility.php 44 2007-07-22 23:55:30Z evolic $
* @link http://www.zeronotice.org
* <i>ZNF_Util_Utility</i> class provides useful methods.
* @author Alessandro Rossini <http://www.alessandrorossini.org>
* @author Graziano Liberati <http://www.liberati.org>
* @copyright 2004-2007 The ZNF Development Team
* @license LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
* @version SVN $Id: Utility.php 44 2007-07-22 23:55:30Z evolic $
* @link http://www.zeronotice.org
* Private constructor to avoid <i>ZNF_Util_Utility</i> object creation.
* Private clonator to avoid <i>ZNF_Util_Utility</i> object clonation.
* Exports a generic array in a well formed XML string.
* @param int $level Level of iteration, determines the depth of the
* array currently processed
* @param string $encoding
static public function arrayToXML($array, $level = 0, $version = '1.0', $encoding = 'utf-8')
$xml = "<?xml version=\"$version\" encoding=\"$encoding\" ?>\n";
// calculate spaces for indentation
for ($i = 0; $i< $level; $i++ ) {
foreach ($array as $name => $value) {
$result .= "$indent<item key=\"$name\">\n";
$result .= self::arrayToXML($value, $level+ 1);
$result .= "$indent</item>\n";
$result .= "$indent<$name>\n";
$result .= self::arrayToXML($value, $level+ 1);
$result .= "$indent</$name>\n";
} elseif (is_int($name) && $value != null) {
$result .= "$indent<item key=\"$name\">" . htmlspecialchars($value) . "</item>\n";
$result .= "$indent<item key=\"$name\"/>\n";
} elseif ($value != null) {
$result .= "$indent<$name/>\n";
* Checks if an email address is valid.
if (!eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$', $email)) {
list ($username, $domain) = split ('@', $email);
$connectAddress = $mxhosts[0];
$out = fgets($connect, 1024);
if (ereg("^220", $out)) {
fputs ($connect, "HELO 82.49.142.198\r\n");
$out = fgets($connect, 1024);
fputs ($connect, "MAIL FROM: <" . $email . ">\r\n");
$from = fgets($connect, 1024);
fputs ($connect, "RCPT TO: <" . $email . ">\r\n");
$to = fgets($connect, 1024);
fputs($connect, "QUIT\r\n");
if (!ereg ("^250", $from ) || !ereg ( "^250", $to )) {
* Checks if an URL is valid and returns it in the correct format.
$domain = preg_replace('/http:\/\/|https:\/\/|http:\/\/www.|https:\/\/www.|^www./', '', $url);
if (!(strstr($url, 'http://') || strstr("Url $url not valid", 'https://'))) {
* Checks a date and returns is timestamp.
static public function getDateTimestamp($year = null, $month = null, $day = null)
return mktime(0, 0, 0, $month, $day, $year);
* Applies addslaslashes PHP function to all the elements of an array.
foreach ($array as &$current) {
$current = self::addAllSlashes($current);
* Applies stripslaslashes PHP function to all the elements of an array.
foreach ($array as &$current) {
$current = self::stripAllSlashes($current);
* Destroys the <i>ZNF_Util_Utility</i> object.</>
* <i>ZNF_Util_UtilityException</i> is the exception type for the <i>ZNF_Util_Utility</i> class.
* <i>ZNF_Util_UtilityException</i> extends the <i>Exception</i> class of PHP5.
* @author Alessandro Rossini <http://www.alessandrorossini.org>
* @author Graziano Liberati <http://www.liberati.org>
* @copyright 2004-2007 The ZNF Development Team
* @license LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
* @version SVN $Id: Utility.php 44 2007-07-22 23:55:30Z evolic $
* @link http://www.zeronotice.org
|