PHP Samples Code

Una funzione che risale di un livello l’url

/**
  Function for modify the global variale $site_URL, to move up one folder level
  return String
*/
private function get_URL_site_upper_folder() {
	
	$result = "";
	//recupero variabile globale
	global $site_URL;
	
	if ( strlen ( $site_URL ) > 0) {
		//eliminazione dell'ultimo carattere delle stringa (dovrebbe sempre essere la slash)
		$strA = substr ( $site_URL , 0,  strlen ( $site_URL ) - 1 );
		//ricerca dell'ultima posizione della slash
		$int_find_position_slash = strrpos($strA, '/');
		//estrazione della nuova stringa dall'inizio alla posizione della slash trovata
		$result = substr ( $strA , 0,  $int_find_position_slash + 1 );
	} 
	
	return $result;
}

Uno script PHP che mescola i valori di un array

<?php
$array_button_key = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");

for ($i = 1; $i <= 100; $i++) {
    $int_index1 = rand(0,9);
	$int_index2 = rand(0,9);
	
	echo 'index = ' . $int_index1 . ";" . $int_index2 . '<br/>';
	
	if ($int_index1 != $int_index2) {
		
		echo "swap data<br>";
		$char_temp = $array_button_key[$int_index1];
		$array_button_key[$int_index1] = $array_button_key[$int_index2];
		$array_button_key[$int_index2] = $char_temp;
		
		echo 'print array ';
				for ($idx = 0; $idx <= 10; $idx++) {

					echo $array_button_key[$idx];
				}
	    echo '<br/>';
	}
}
?>
This entry was posted in PHP, Programming Languages. Bookmark the permalink.