Tips & Tricks

@@Php_logo@@

PHP

PHP scripts

Tips

Date format

Format character Example
c 2004-02-12T15:19:21+00:00
Y-m-d\Th-i-s.e 2025-07-29T11:57:22.Europe/Copenhagen
Y-m-d\Th-i-s.P 2025-07-29T11:57:22.+02:00

Recursive functions

Do not use “call to self” by name inside recursive functions. Use variable functions instead:

function test($i) {
   static $__this = __FUNCTION__;
   if($i > 5) {
       echo $i. "\n";
       $__this($i-1);
   }
}

Source: @@Stackoverflow_logo@@ Can you make a PHP function recursive without repeating its name?

@@Stackoverflow_logo@@ Can I make a PHP function “private” in a script?

$func = function () { ... }. Then you can use it as $func();.

Duration

See Timing

Modules

PHP 8. which gives error with imagettfbbox. it has to be replaced with imageftbbox

extension=gd
;2024-03-13 19:11:05/ErBa ImageMagick
extension=php_imagick.dll

Ini

CA certificates for SSL

Certificates are available from: https://curl.se/docs/caextract.html

Run this script in elevated state (CMD - not you). The script uses CURL @@Curl_icon@@ to download the certificates.

:getCacert
    CD "%ProgramFiles%\php"
    SET CACERTDIR="%ProgramFiles%\php\cacert"
    :: Create dir if not exist

    CD %CACERTDIR% 2>NUL || (ECHO %CACERTDIR% & MKDIR %CACERTDIR% & CD %CACERTDIR%)
    curl --etag-compare etag.txt --etag-save etag.txt --remote-name https://curl.se/ca/cacert.pem
    DIR
GOTO :EOF

Modify php.ini to enable the SSL:

- ;extension=openssl
---
+ ;2024-11-06T22:25:48/ErBa
+ extension=openssl
+ ;2023-10-11/ErBa Enable https requests https://stackoverflow.com/a/12587073
+ ;2024-07-19T08:31:58
+ ;;extension=openssl
[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
- ;curl.cainfo =
+ ;2024-11-06T23:58:54/Erba curl: https://curl.se/docs/caextract.html
+ curl.cainfo ="C:\Program Files\php\cacert\cacert.pem"
[openssl]
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the identity of SSL/TLS peers. Most users should
; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
- ;openssl.cafile=
+ ;2024-11-06T23:59:20/ErBo curl: https://curl.se/docs/caextract.html
+ openssl.cafile="C:\Program Files\php\cacert\cacert.pem"