Creating a PHP Class with Type Hinting and Return Types How to create a PHP class with strict type, getters and setters and method return types. class automobile { public int $speed; function __construct() { $this->speed = 10; } function…
Creating a PHP function in PHP 8 How to create a function / method in PHP with type hinting and return types. function is_greater_than(int $x, int $y) : bool { return ($x > $y) ? true : false; } is_greater_than(1,2);
Validate an email with PHP and Regex Works with preg_match and preg_match_all which use the PCRE Library. $email = ‘editor@devtutorials4u.co.uk’ if (!preg_match(‘^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$^’, $email)) { echo ‘The email address you entered was invalid.’; }