Code snippets
You will find here 126 code snippets I find useful so I don't have to Google ™ or Stackoverflow ™ them when I need. There are also code snippets I always forget! 😁 Sometimes, related links to the code will be available. The main difference with other random snippets you will find on the web is that in most cases (for the Symfony related ones) you will be able to run them directly from this website to check the output so you can verify it works as expected ™.
In this snippet, we see how to trim the first word of a string with PHP. In the following example, we can't use a simple replace f...
PHP
Published on 2021-11-28 • Modified on 2021-12-03
In this snippet, we see how to generate a random string with the Symfony string component. There is this static function fromRando...
Symfony
Published on 2021-11-21 • Modified on 2021-11-21
In this snippet, we see how to test the current PHP version. The most straightforward way is to use the PHP_VERSION_ID constant. I...
PHP
Published on 2021-11-19 • Modified on 2021-11-19
In this snippet, we see how to get the first character of a string with PHP and Symfony. In the first part, we see how to use the ...
PHP
Published on 2021-11-12 • Modified on 2021-11-12
In this snippet, we see how to get the activated PHP extensions list with their versions. I use a one-line statement with an arrow...
PHP
Published on 2021-10-07 • Modified on 2021-10-07
In this snippet, we see how to inspect the content of a string using the file_put_contents PHP function. Sometimes, when you use t...
PHP
Published on 2021-09-05 • Modified on 2021-09-05
In this snippet, we see how to get a human-readable version of the PHP error_reporting directive value. The code is mainly extract...
PHP
Published on 2021-08-20 • Modified on 2021-08-20
In this snippet, we see how to get the physical path of a temporary PHP file. In this case, we use the tmpfile() function to creat...
PHP
Published on 2021-07-25 • Modified on 2021-07-25
In this snippet, we see how to create a unit test for a Twig template. This template contains a simple if tag like this: {% if cas...
Twig
Published on 2021-07-02 • Modified on 2021-07-02
In this snippet, we see a typical PHP interface. I have added comments inside about what is allowed are not. For each case, I have...
PHP
Published on 2021-06-15 • Modified on 2021-06-15