PHP practice: string comparison

PHP is pretty good at information processing. The language syntax is represented by a full-featured set of functions for comparing, processing strings, and comparison operators.

php string comparison




Any algorithm is a sequence of choices and actions. But before you make a choice, you need to compare something with something. Strings are the most capacious, efficient and practical mechanism for controlling the algorithm. Rows - a variant of data representation. And data is the main subject of "concern" of any algorithm.

Conventional comparison-action logic

, , PHP . - , , , ( ).

, gettype () 'integer' 'double'.

php compare two lines




is_int () is_numeric (). , , , ( 'string', , ).





- , PHP ('==', '===', '!=', ...) . , , . - .

php string comparison operators




, PHP . , . .

PHP- "" strpos () - , . , .

, - .

Author's example is not a picture




$cResult = scCheckFileName($cStr) 'true', , . '.docx' : , '_', '-'.





: $cPtr = '/^([a-zA-Z...0-9\-\_]{4,239})\.(html|js|css|png|jpg|docx|txt){1}$/u'. (, PHP " , ") html, js, css, ...

strpos () preg_match () - . . - , .

PHP:

- , . , - . .

PHP: int strcmp (s1, s2).

:

  • 0 - ;
  • -1 - ;
  • 1 - .

, , PHP ( ) . strpos (), .

strcmp () - . , PHP strcasecmp(). .

, . PHP ( ) strncmp (s1, s2, N). N-. strcmp ().

,

. , , , .

php string comparison function




. implode(array, symbol), : $margins1 = implode(', ', $style->getInnerMargin()); ... / ...; $margins2 = implode(', ', $style->getInnerMargin()) .

PHP- : $check = strcmp ($margins1, $margins2) , - ( ). , . .

PHP ( ) - .

. , , . (put) (get).

, . "" , , .

php string and number comparison




, . (). , , , .

PHP , , . .

Sure, the functionality is good, but its use can be transferred to the semantic part of the code, to objects. When an algorithm is presented as a system of interaction of objects, it looks much better than a sequence of comparisons and actions in a direct, sequential, classical style.




All Articles