Code snippets

You will find here 7 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 ™.

This is a simple trick to get a random value of an array created on the fly. Of course, in this case...

PHP
Published on 2019-09-09 • Modified on 2019-09-09

 Show me the code


This is another example where the constant Twig function can be helpful. In this case we get the \Da...

Twig
Published on 2019-08-18 • Modified on 2019-08-18

 Show me the code


Sometimes when using the PHP date function you need to use characters how are usually reserved to be...

Twig
Published on 2019-08-14 • Modified on 2019-08-14

 Show me the code


I always forget how to do this! 🤔 So we will load the XML with a PHP DOMDocument object then we will...

PHP
Published on 2019-07-18 • Modified on 2019-07-18

 Show me the code


It is sometimes useful to have these information. In this project I am displaying them to show you t...

Symfony
Published on 2019-01-15 • Modified on 2019-01-15

 Show me the code


Sometimes you must restrict an action to be accessible with a given method only. That is the case fo...

Symfony
Published on 2018-09-26 • Modified on 2018-09-26

 Show me the code