function

Convert XML to array


/**
* Converts XML to array
*
* @param unknown_type $url
* @param unknown_type $get_attributes
* @param unknown_type $priority
* @return unknown
*/
function xml2array($url, $get_attributes = 1, $priority = 'tag')
{
$contents = "";
if (!function_exists('xml_parser_create'))
{
return array ();
}
$parser = xml_parser_create('');
if (!($fp = @ fopen($url, 'rb')))
{
return array ();
}
while (!feof($fp))
{
$contents .= fread($fp, 8192);
}
fclose($fp);
xml_parser_set_option($pars

Check if URL exist

This function checks if a given URL is valid by using fsockopen.


function is_valid_url ($url){
$url = @parse_url($url);
if ( ! $url) {
return false;
}

$url = array_map('trim', $url);
$url['port'] = (!isset($url['port'])) ? 80 : (int)$url['port'];
$path = (isset($url['path'])) ? $url['path'] : '';

if ($path == ''){
$path = '/';
}

$path .= ( isset ( $url['query'] ) ) ?

Loop all terms in a vocabulary

function list_all_countries($vid) {
$vid = 1; // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
$pole = array();
$items = array();
$terms = taxonomy_get_tree($vid);

foreach ( $terms as $term ) {
$count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid));
$pole[]=Array (l($term->name, "taxonomy/term/$term->tid") .

Human readable password function


/**
* Creates human readable passwords
* TODO: filter not desired phrases
* @param unknown_type $length
* @return unknown
*/

function com_dir_create_password($length = 10){
global $strength;

$conso = array("b","c","d","f","g","h","j","k","m","n","p","r","s","t","v","w","x","y","z");
$numeric = array(2,3,4,5,6,7,8,9);
$vocal = array("a","e","i","o","u");
$password = "";
srand ((double)microtime()*1000000);

$templength = ($length % 2) ? $length -1 : $length -2;
$max = $templength/2;

for($i=1; $i

Hide admin fields


/**
* Hide admin fields from form
* Called from _form_alter
*
* @param unknown_type $form
*/
function __hide_adminfields(&$form) {

$form['admin_only'] = array(
'#type' => 'fieldset',
'#title' => t('Admin settings'),
'#weight' => 100,
'#access arguments' => array('special_administration'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);

//Hide admin fields in one fieldset
$form['admin_only']['options'] = $form['options'];
$form['admin_only']['menu'] = $form['menu'];

How to create a function to determine if a value is numeric in MySQL/SQL

This is how you can create a function in MySQL to determine if a selected value is numeric or not.

<?php
CREATE
FUNCTION IsNumeric (sIn varchar(1024)) RETURNS tinyint DETERMINISTIC
RETURN sIn REGEXP '^(-|\\+){0,1}([0-9]+\\.[0-9]*|[0-9]*\\.[0-9]+|[0-9]+)$';

UPDATE nodemap SET`nodemap_city` = CONCAT(SUBSTR(`nodemap_city`, 1, 3), ' ', SUBSTR(`nodemap_city`, 4, 2), SUBSTR(`nodemap_city`, 6)) WHERE IsNumeric(SUBSTR(`nodemap_city`, 1, 5)) = 1 LIMIT 1;
?>

Pages