PHP🔗
เป็นภาษา server side language
https://laragon.org/index.html
#php --ini // PHP Cli in Command
#php -m // Module
#php -a //Interactive shell
print_r(get_loaded_extensions());
php_info(); //Check Information PHP
Composer🔗
package manger ของภาษา php ใช้ในการ manage dependencies
Escape Sequence🔗
\n //New Line
\" //Double quote
\r //Carriage Return
\t //Tab
\\ //Blackslash
\$ //Dollar sign
Objects🔗
ob_start(); //Turn on output buffering
ob_get_contents(); //Return the contents of the output buffer
ob_end_clean() // Clean output buffer and turn off output buffering
ob_end_flush() // Flush(send)output buffer,turn off output buffering
Explode แยกข้อความ🔗
$url_request = explode ("/",$_SERVER['REQUEST_URI']);//แยก string เป็น array ด้วย '/'
print $url_request[1];
Regular Expression🔗
$url = "https://example.org/path/here";$matches = [];
$regex = "@^(http(s?))://(.*)$@i";
if (preg_match($regex, $url, $matches)) {
var_dump($matches);
}
Decode🔗
rawurldecode🔗
echo rawurldecode('foo%20bar%40baz'); // foo bar@baz
Url Decode🔗
$value = "%e0%b8%a3%e0%b8%b5%e0%b8%a7%e0%b8%b4%e0%b8%a7%e0%b8%a5%e0%b8%b9%e0%b8%81%e0%b8%84%e0%b9%89%e0%b8%b2-%e0%b9%82%e0%b8%8a%e0%b9%8a%e0%b8%84%e0%b8%ad%e0%b8%b1%e0%b8%9e";
$normal = urldecode($value);
$normal_ex = explode('-',$normal);
OOP🔗
SOLID Principles🔗
Single-responsibility principle🔗
เป้าหมายเดียวในการทำงาน
Open-closed principle🔗
Liskov substitution principle🔗
Interface segregation principle🔗
Dependency Inversion Principle🔗
Error Handling🔗
catch🔗
Exception $e LogicException $e RuntimeException $e
try
{
$div = invert(0);
}
catch (LogicException $e) {}
https://apzentral.github.io/php-the-right-way/ https://secure.phabricator.com/book/phabflavor/article/php_pitfalls/ http://www.expertphp.in/category/php?page=2
https://phptherightway.com/pages/Design-Patterns.html