Php
/
String
- 1 Basics 5
-
Quotes S
-
Constants S
-
Control structures S
-
Reference S
-
Number systems S
- 2 Variables 4
-
Definition S
-
Variable variable S
-
Exists S
-
Type casting S
- 3 Operators 5
-
Aritmetic S
-
Bitwise S
-
String S
-
Comparison S
-
Logical S
- 4 Function 4
-
Definition S
-
Anonymous S
-
Reference S
-
Variable arguments S
- 5 Array 7
-
Basics S
-
Operations S
-
Create S
-
Search S
-
Modify S
-
Sort S
-
Storage S
- 6 String 9
-
Basics
-
Compare
-
Search
-
Replace
-
Format
-
Regexp
-
Parse
-
Formating
-
Json
- 7 Streams 6
-
File open
-
Read file
-
Read csv
-
File contents
-
Context
-
Ob_start
- 8 Oop 6
-
Object instantiation S
-
Class constructor
-
Interfaces, abstract
-
Resource visibility
-
Class constants
-
Namespaces
- 9 Features 9
-
Autoload
-
Class reflection
-
Magic methods
-
Exceptions S
-
Late static binding
-
Type hinting
-
SPL
-
PHPUNIT
-
PHAR
- 10 Versions 2
-
Php7.4 S
-
Php8.0 S
- 11 Http 4
-
Headers
-
File Uploads
-
Cookies
-
Sessions
- 12 Design Patterns 4
-
Singleton Pattern S
-
Observer Pattern
-
Strategy Pattern
-
Registry
- 13 Modern Php 8
-
Composer S
-
Slim Framework
-
Autoloader
-
Package
-
Releases
-
Generators
-
Dependency Injection
-
Middleware
- 14 Create Framework 7
-
App
-
Http Foundation
-
Front Controller
-
Routing
-
Render Controller
-
Resolver
-
SoC
- 15 Frameworks 4
-
Symfony v5
-
Laravel v8
-
Laminas v3
-
Codeigniter v4
- 16 Composer 5
-
Guzzle
-
Carbon
-
Faker
-
Math
-
Requests
- 17 Symfony 6
-
Routes S
-
Annotations
-
Flex
-
Controllers
-
Doctrine
-
Templating
R
Q
Strict
Not using strict operator === can lead to variable type problems.
code
$string = "123abc";
echo $string == 123 ? 'true' : 'false'; // true (incorect)
// "123abc" -> (int) "123abc" -> 123
echo $string === 123 ? 'true' : 'false'; // false (corect)
Safe
Binary safe string comparison. Returns < 0 if str1 is less than str2 Returns > 0 if str1 is greater than str2 Returns 0 if they are equal
code
echo strcmp("a", "a"); // 0
echo strcasecmp("A", "a"); // 0 (case insensitive)
echo strcmp("A", "a"); // -1
echo strcmp("a", "A"); // 1
Binary safe string comparison (n characters)
code
$str = "hello John";
echo strncasecmp($str, "Hello World", 5); // 0
substr_compare()
code
// substr_compare($main_str, $str, $offset, $length, $flag_case)
echo substr_compare("abcde", "bc", 1, 2); // bc, bc = 0
echo substr_compare("abcde", "de", -2, 2); // de, de = 0
echo substr_compare("abcde", "cd", 1, 2); // bc, cd = -1
echo substr_compare("abcde", "bc", 1, 3); // bcd, bc = 1
// main_str offset is less than str offset
echo substr_compare("abcde", "BC", 1, 2, true); // bc, bc = 0
// Third parameter - case insenstivity
echo substr_compare("abcde", "abc", 5, 1); // Warning
// Offset is equal or greater than string legth
Similar
similar_text() returns the number of matching chars in both strings.
code
echo similar_text("cat", "can"); // 2
similar_text("cat", "can", $percent);
echo $percent; // 66,6
Levenshtein
Minimal number of characters you have to replace. Insert or delete to transform str1 into str2.
code
echo levenshtein('cat', 'can'); // 1
Soundex
Words pronounced similarly produce the same soundex key. Can be used to simplify searches in databases.
code
echo soundex('wise'); // W200
echo soundex('ways'); // W200
Metaphone
More precise than soundex. It is based in english pronunciation rules - limited global use.
code
echo soundex('programming') == soundex('programmer'); // TRUE
// P626 == P626
echo metaphone('programming') != metaphone('programmer'); // TRUE
// PRKRMNK != PRKRMR
➥ Questions
Last update: 402 days ago