Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
Design
/
fileman
/
Fusion
/
Table
:
test_valeur.php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php // OK //$text = "78&7"; //$newtext = preg_replace("/[^A-Za-z0-9 ]/", "", $text); //echo " +++++ " .$newtext; //echo "<br>"; //echo "<br>"; // ?? $cleanString = preg_replace('/[^A-Za-z0-9\-]/', '', $inputString); // ?? $cleanString = filter_var($text, FILTER_SANITIZE_STRING); // ?? echo $cleanString; // Output: Hello, World! $array_val = array(" 51 78 ", "78&7", "747Z", "747z", "1747", ".1792.AqP.44." , "AZerTY", "8.15", "123.78.94" , ".514" , "357."); $array_process = array(); // supprimer les espaces en début et fin de chaines // les caractéres spéciaux ne sont pas pris en compte ???? for ($i = 0; $i < count($array_val); $i++) { $newtext = preg_replace("/[^A-Za-z0-9. ]/", "", $array_val[$i]); $array_val[$i] = $newtext; } echo "<br>"; echo "<br>"; echo "<pre>"; print_r($array_val); echo "</pre>"; echo "<br>"; echo "<br>"; for ($i = 0; $i < count($array_val); $i++) { $new_str = str_replace(' ', '', $array_val[$i]); $array_val[$i] = $new_str; echo "--+++---> " .$i . " " .$array_val[$i]; $newtext = preg_replace("/[^A-Za-z0-9 ]/", "", $array_val[$i]); echo " +++++ " .$newtext; if(contains_letters($array_val[$i]) ) { echo " Contient des lettres "; // on autorise uniquement les nombres $remove_letter = preg_replace("/[^0-9]/", "", $array_val[$i] ); //echo " Contient des lettres " .$remove_letter; /// $remove_letter = preg_replace("/[^A-Za-z0-9 ]/", "", $array_val[$i]); //$remove_letter = preg_match("/^[a-zA-Z0-9]+$/", $array_val[$i]); // $remove_letter = preg_replace("/[^a-zA-Z0-9]/", "", $array_val[$i]); // $remove_letter = preg_replace("/[^A-Za-z0-9 ]/", "", $array_val[$i]); // [0 9] 48 - 57 // [a z] 97 - 122 // [A Z] 65 - 90 if( strlen($remove_letter) == 0) { $array_process[$i] = "vide"; } else { $array_process[$i] = $remove_letter; } echo $remove_letter; } else { echo " Ne contient aucunes lettres "; $pieces = str_split($array_val[$i]); $test = point_exploration($pieces); // plusieur point ? if( $test == true) { $array_process[$i] = "vide"; } // il y a un point else { // supprimer le point en premiére position if( $pieces[0] == chr(46) ) { $changed = substr($array_val[$i], 1); $array_process[$i] = $changed; //echo $array_testing[$i] ." devient " .$changed; //echo "</br>"; //$array_convert[$i] = $changed; //$flag = true; } else if( end($pieces) == chr(46) ) { $changed = substr($array_val[$i], 0, -1); $array_process[$i] = $changed; //echo $array_testing[$i] ." devient " .$changed; //echo "</br>"; //$array_convert[$i] = $changed; //$flag = true; } else { $array_process[$i] = $array_val[$i]; } } } echo "<br>"; } echo "<br>"; echo "<br>"; echo "<pre>"; print_r($array_process); echo "</pre>"; echo "<br>"; echo "<br>"; $myVar = "747Z"; //echo $myVar ." contient des lettres " .preg_match('/[a-zA-Z]+/', $myVar); $length_string = strlen($myVar); if(contains_letters($myVar) ) { echo $myVar ." contient des lettres "; // on autorise uniquement les nombres $res = preg_replace("/[^0-9]/", "", $myVar ); $total_nombre = strlen($res); echo $length_string ." " .$total_nombre ; } else { echo $myVar ." Ne contient pas des lettres "; } echo "<br>"; $myVar = "747z"; //echo $myVar ." contient des lettres " .preg_match('/[a-zA-Z]+/', $myVar); if(contains_letters($myVar) ) { echo $myVar ." contient des lettres "; echo preg_replace("/[^0-9]/", "", $myVar ); } else { echo $myVar ." Ne contient pas des lettres "; } echo "<br>"; $myVar = "1747"; //echo $myVar ." contient des lettres " .preg_match('/[a-zA-Z]+/', $myVar); if(contains_letters($myVar) ) { echo $myVar ." contient des lettres "; } else { echo $myVar ." Ne contient pas des lettres "; } echo "<br>"; $myVar = "AZERTY"; //echo $myVar ." contient des lettres " .preg_match('/[a-zA-Z]+/', $myVar); if(contains_letters($myVar) ) { echo $myVar ." contient des lettres "; // on autorise uniquement les nombres $res = preg_replace("/[^0-9]/", "", $myVar ); echo strlen($res); } else { echo $myVar ." Ne contient pas des lettres "; } echo "<br>"; /* if('string1' == 'string1') { echo 'Strings match.'; } else { echo 'Strings do not match.'; } if($str == $res) { echo 'Strings OK'; } else { echo 'Strings error'; } */ $array_testing = array("1235", "aze", "8.15", "AZ9.78", ".127.Q78.2.5", ".514", "357."); $array_convert = array(); $flag = true; for ($i = 0; $i < count($array_testing); $i++) { echo "-----> " .$array_testing[$i]; echo "<br>"; $pieces = str_split($array_testing[$i]); // $test = point_exploration($pieces); /*if( $test == true ) { $array_convert[$i] = "Bad"; //$flag = true; }*/ // supprimer le point en premiére position if( $pieces[0] == chr(46) ) { $changed = substr($array_testing[$i], 1); echo $array_testing[$i] ." devient " .$changed; echo "</br>"; $array_convert[$i] = $changed; $flag = true; } if( end($pieces) == chr(46) ) { $changed = substr($array_testing[$i], 0, -1); echo $array_testing[$i] ." devient " .$changed; echo "</br>"; $array_convert[$i] = $changed; $flag = true; } /*else { /*if(flag == false) { echo " Analyse ----> " .$array_testing[$i]; echo "</br>"; $res = preg_replace("/[^0-9.]/", "", $array_testing[$i] ); $array_convert[$i] = $res; //echo $res; //echo "</br>"; $res = compare($array_testing[$i], $res); if( $res == "bad") { // echo "ddddd" .$res; // echo "</br>"; $array_convert[$i] = "bad"; } }*/ /*}*/ } echo " ------- "; echo " ------- "; echo " ------- "; print_r($array_convert); //plusieurs points dans la chaine $str = ".127.78.2.5"; $pieces = str_split($str); $cpt = 0; $flag_not_valide_point = false; for ($i = 0; $i < count($pieces); $i++) { if( $pieces[$x] == chr(46) ) { // compte les points qui sont inclus dans la chaine $cpt++; if( $cpt >= 2 ) { $flag_not_valide_point = true; echo "Trop "; echo "</br>"; break; } } } $str = "1235"; $res = preg_replace("/[^0-9.]/", "", $str ); echo $res; compare($str, $res); echo "</br>"; $str = "aze"; $res = preg_replace("/[^0-9.]/", "", $str ); echo $res; compare($str, $res); echo "</br>"; $str = "8.15"; $res = preg_replace("/[^0-9.]/", "", $str ); echo $res; compare($str, $res); echo "</br>"; $str = "AZ9.78"; $res = preg_replace("/[^0-9.]/", "", $str ); echo $res; compare($str, $res); echo "</br>"; $str = ".127.78.2.5"; $res = preg_replace("/[^0-9.]/", "", $str ); echo $res; compare($str, $res); echo "</br>"; $str = ".357"; $res = preg_replace("/[^0-9.]/", "", $str ); echo $res; compare($str, $res); echo "</br>"; echo "</br>"; echo " ------- "; echo "</br>"; echo "</br>"; $str = ".357"; $pieces = str_split($str); // supprimer le point en premiére position if( $pieces[0] == chr(46) ) { $str1 = substr($str, 1); echo $str ." devient " .$str1; echo "</br>"; } echo " ------- "; echo "</br>"; echo "</br>"; $str = "357."; $pieces = str_split($str); // supprimer le point en derniere position if( end($pieces) == chr(46) ) { $str1 = substr($str, 0, -1); echo $str ." devient " .$str1; echo "</br>"; } echo " ------- "; echo "</br>"; echo "</br>"; //plusieurs points dans la chaine $str = ".127.78.2.5"; $pieces = str_split($str); $cpt = 0; $flag_not_valide_point = false; for ($i = 0; $i < count($pieces); $i++) { if( $pieces[$x] == chr(46) ) { // compte les points qui sont inclus dans la chaine $cpt++; if( $cpt >= 2 ) { $flag_not_valide_point = true; echo "Trop "; echo "</br>"; break; } } } //.127.78.2.5 //127.78.2.5 //$array = array(1, "hello", 1, "world", "hello"); echo " ---> " .$str; echo "</br>"; $resultArray = array(); $resultArray = array_count_values($pieces); //print_r(array_count_values($pieces)); //echo "</br>"; $all_keys = array_keys($resultArray); echo " All keys " . print_r($all_keys); echo "</br>"; echo " ++++ " .$all_leys[0]; if( $all_leys[0] == chr(46) ) { echo "klklhklhklhkkkl"; } echo "</br>"; //print_r(array_keys($resultArray)); /*for ($x = 0; $x < count($resultArray); $x++) { echo " -----> " .$resultArray[$x]; echo "</br>"; if( $resultArray[$x] == chr(46) ) { echo " Zoulou " .$resultArray[chr46]; } }*/ // OK //echo preg_replace('~\D~', '', $str); //echo "</br>"; //echo "</br>"; echo test("1235"); echo "</br>"; echo test("aze"); echo "</br>"; echo test("8.15"); echo "</br>"; echo test("AZ9.78"); echo "</br>"; echo test(".127.78.2.5"); echo "</br>"; echo test(".357"); echo "</br>"; echo "</br>"; echo "</br>"; echo "</br>"; $str = "A"; if( $str == chr(65) ) { echo "Bingo"; echo "<br>"; } echo preg_match("/^[a-z0-9.]+$/i", "123"); echo "<br>"; echo preg_match("/^[a-z0-9.]+$/i", "aze"); echo "<br>"; echo preg_match("/^[a-z0-9.]+$/i", "123.78"); echo "<br>"; echo preg_match("/^[a-z0-9.]+$/i", "12a3.Z78"); echo "<br>"; echo "<br>"; $str = '123454321'; $pattern = '/^[0-9]+$/'; if ( preg_match($pattern, $str) ) { echo 'string contains only digits'; } else { echo 'string does not contain only digits'; } /*$pieces = str_split("789123"); for ($i=0; $i<count($pieces); $i++) { echo $pieces[$i] ."<br>"; if( $str != chr(48) || $str != chr(49) || $str != chr(50) || $str != chr(51) || $str != chr(52) || $str != chr(53) || $str != chr(54) || $str != chr(55) || $str != chr(56) || $str != chr(57) ) { echo "Probléme"; echo "<br>"; } } */ echo "<br>"; echo "<br>"; echo "<br>"; echo hasNumbers("123"); echo "<br>"; echo hasNumbers("aze"); echo "<br>"; echo hasNumbers("0a8kp"); echo "<br>"; $string = "789"; if (preg_match('~[0-9]+~', $string)) { echo 'string with numbers'; echo "<br>"; } $string = "7.89"; if (preg_match('~[0-9]+~', $string)) { echo 'string with numbers'; echo "<br>"; } $string = "a8"; if (preg_match('~[0-9]+~', $string)) { echo 'string with numbers'; echo "<br>"; } $string = "agdf"; if (preg_match('~[0-9]+~', $string)) { echo 'string with numbers'; echo "<br>"; } //echo intval("42"); //echo "<br>"; //echo intval("AZ"); //echo "<br>"; //echo intval("10.57"); $error = "78.7.21"; $tests = array( "42", 1337, 0x539, 02471, 0b10100111001, 1337e0, "0x539", "02471", "0b10100111001", "1337e0", "not numeric", array(), 9.1, $error, null, '', ); foreach ($tests as $element) { if (is_numeric($element)) { echo var_export($element, true) . " is numeric", PHP_EOL; } else { echo var_export($element, true) . " is NOT numeric", PHP_EOL; } echo "<br>"; } function contains_letters($string) { return preg_match('/[a-zA-Z]+/', $string); } function compare($string1, $string2) { $status = ""; if (strcmp($string1, $string2) == 0) //if ( $string1 == $string2) { echo 'Equal'; echo "<br>"; $status = "good"; } else { echo 'Differente'; echo "<br>"; $status = "bad"; } return($status); } function point_exploration($pieces) { $cpt = 0; $flag_not_valide_point = false; for ($i = 0; $i < count($pieces); $i++) { if( $pieces[$i] == chr(46) ) { // compte les points qui sont inclus dans la chaine $cpt++; if( $cpt >= 2 ) { $flag_not_valide_point = true; break; } } } return $flag_not_valide_point; } function hasNumbers($strValue) { return preg_match('/[0-9]/', $strValue); // === 1; } function test($val) { $pieces = str_split($val); //echo "<pre>"; //print_r($pieces); //echo "</pre>"; $count_point = substr_count($val, '.'); echo " ----> Nb points " .$count_point ." +++++++ "; echo "</br>"; /*if( $pieces[0] == chr(46) ) { $detect_error = true; echo " TRACE1 "; }*/ //else //{ //echo " TRACE2 "; 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; //$detect_error = "lulu"; //echo "fdgljqjglkfjgklfjqljqjsdl " .$detect_error ; } //} if( $detect_error ) { $retour = "Erreur"; } else { $retour = "OK"; } return $retour ." " .$val; } function filtre_ascii_code() { } ?>