Archive

Posts Tagged ‘php’

Checking on repeat number

October 4th, 2008

There is this validation i need to do today , to check the value is it a repeat number, example 111111 or 22222 is not allow, but 1112222 or 222333 is ok. So this is what i come out with

$same=(substr_count($text,$text[0]) == strlen($text))? TRUE : FALSE;

  • what does function substr_count(words,character) do ? if actually checking the character that you supply through the entire words and return the total number that character been use.
  • a word is actually an array of character , that’s why $text[0] means the first character in the word
  • strlen() is use to return total number of character in a word
  • one of the good tactic i learn here Variable=(Condition):condition true value ? condition false value

By using the first char compare to the whole words, it should return me the same number of total length of the word, because what i try to find out is is this word full with the same number.

Snippets ,