Measuring weight for a word on a page
Code for calculation weight for a word in its context on a page.
Code for calculation weight for a word in its context on a page.
/**
* 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
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'] ) ) ?
This function lets you search for a value in any level of an multiple array. One advantage is that it breaks the search when it finds the value.
function list_all_countries($vid) { foreach ( $terms as $term ) {
$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);
$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") .
/**
* 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<=$max; $i++)
This function traverse an multidimensional array recursively. You know the key and what level.
/**
* Hide admin fields from form
* Called from
*
* @param unknown_type $form
*/
function _
$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'];
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;
?>
This function makes all characters upper case, even the swedish åäö.
But the most convenient way to do this is to use mb_strtoupper or mb_strtolower, available in PHP 4 >= 4.3.0 or PHP 5.