⬅️ **[[$-Software|Software]]**
***
# PHP
- [[PHP_Kurzreferenz_PHP_A4_einseitig.pdf]]
- [[PHP_referenz_web_I.pdf]]
## Funktionen und Code Snippets
- [PHP: date - Manual](https://www.php.net/manual/de/function.date.php)
- [PHP: DateTimeInterface::format - Manual](https://www.php.net/manual/de/datetime.format.php)
- [PHP: json_encode - Manual](https://www.php.net/manual/en/function.json-encode.php)
- [PHP preg_replace() Function](https://www.w3schools.com/php//func_regex_preg_replace.asp)
- [PHP: htmlspecialchars - Manual](https://www.php.net/manual/de/function.htmlspecialchars.php)
- [PHP: imagecreatetruecolor - Manual](https://www.php.net/manual/en/function.imagecreatetruecolor.php)
### Use `$_POST` variables
```php
// old
//if (isset($_POST['action'])) { $aktion=$_POST['action']; } else { $aktion=$_GET['action']; }
// new
if (null !== filter_input(INPUT_POST, 'action')) { $aktion= filter_input(INPUT_POST, 'action'); } else { $aktion= filter_input(INPUT_GET, 'action'); }
```
### Logging into file
```php
// Log file to see the Request information
// replace password with ******
$getData = preg_replace('/"password":"[a-z0-9]+"/','"password":"******"',json_encode($_GET));
$postData = preg_replace('/"password":"[a-z0-9]+"/','"password":"******"',json_encode($_POST));
$log = date("Y-m-d H:i:s")." Request - Action: ".$aktion." - User: ".$user." - ".$_SERVER['REMOTE_ADDR'].PHP_EOL.
(sizeof($_GET) != 0 ? ' GET: '.$getData.PHP_EOL :'').
(sizeof($_POST) != 0 ? ' POST: '.$postData.PHP_EOL :'').
"-------------------------".PHP_EOL;
file_put_contents('./log_MCE_'.date("Y-m-d").'.log', $log, FILE_APPEND);
```
## Version Upgrades
- [PHP: Migration von PHP 7.3.x auf PHP 7.4.x - Manual](https://www.php.net/manual/de/migration74.php)
- [PHP: Migration von PHP 7.4.x auf PHP 8.0.x - Manual](https://www.php.net/manual/de/migration80.php)
- [PHP: Migration von PHP 8.0.x auf PHP 8.1.x - Manual](https://www.php.net/manual/de/migration81.php)