File "ajax_request.php"

Full Path: /home/analogde/www/Outlook/Fusion/Table/ajax_request.php
File size: 1.24 KB
MIME-type: text/x-php
Charset: utf-8

<?php

	if(isset($_POST["joueur"]))
	{
		
		
		/*echo "-----> " .gettype( $_POST["joueur"] );
		
		if (is_numeric( $_POST["joueur"] )) 
		{
			echo var_export($element, true) . " is numeric", PHP_EOL;
		} else 
		{
			echo var_export($element, true) . " is NOT numeric", PHP_EOL;
		}*/
		
		echo test( $_POST["joueur"]); 
	}
	
function test($val)
{
	$pieces = str_split($val);
	
	$count_point = substr_count($val, '.');
	
	//echo "  ----> Nb points " .$count_point ."  +++++++  ";
	//echo "</br>";
		
	if( $count_point < 2 ) // pas de point ou 1
	{
			$detect_error = false;
			
			for ($i=0; $i<count($pieces); $i++)
			{
				//echo "---> $i " .$pieces[$i] ."<br>";
				if( $pieces[$i] == chr(46)   )
				{
					$detect_error = false;
					if( $i == 0 ) // erreur si on commence par un point 
					{
						$detect_error = true;
						break;
					}						
				}
				else if( $pieces[$i] >= chr(48) && $pieces[$i] <= chr(57)  )
				{
					$detect_error = false;
				}	
				else
				{
					$detect_error = true;
					break;
				}			
			}
	}
	else 
	{
			$detect_error = true;
	}		
	
	if( $detect_error )
	{
		$retour = "Erreur";
	}
	else
	{
		$retour = "OK";
	}		
	return $retour ." " .$val;
	
}

?>