PHP Spaceship Operator <=>

Code sur écran d'ordinateur

A little-known but very useful operator, for example to sort an array, is the spaceship operator: <=> It compares two values and returns an integer (-1, 0, 1) depending on the result. $a < $b returns -1 $a = $b returns 0 $a > $b returns 1 One way to see it is here: https://3v4l.org/WcRSo … Read more

PHP, DOMdocument and xPath to spar an xml file

Code sur écran d'ordinateur

When we have to process a very large XML, it is unfortunately not possible to use SimpleXML. Fortunately for this, we can use DOMDocument. To do this, just load the desired file and initialize xpath on it with DOMXPath. $document – new DOMDocument(); $document-load ($file); $xpath – new DOMXPath ($document); If the XML in question … Read more

PHP and simpleXML

Code sur écran d'ordinateur

When you want to process an XML file in PHP, there are two possibilities: either we use SimpleXML or we go through DOMDocument. In this article I will deal more specifically with SimpleXML. To load a file, just use the simplexml_load_file method $xml – simplexml_load_file ($file); By doing so, you get a SimpleXMLElement. If the … Read more

PHP – CodeIgniter how to create and use a model

MacBook avec code sur un bureau

Looking at the structure of CodeIgniter we see that there is a folder called application/models. It is in this one that we will create our model. For a model to be usable as such, it must extend CI_Model. class ScoresModel extends CI_Model function __construct Call the Model constructor parent::__construct(); $this-load-database(; } function getAllScores() $query – … Read more

PHP – Create a REST API with CodeIgniter

Code sur écran d'ordinateur

Introduction CodeIgniter is a fairly simple framework for PHP. Compared to its big brothers such as Zend or Yii, it has the advantage of being small and very simple to get to grips with. For me, currently the best for small projects such as creating a REST-API. Installation To start, go download the official version … Read more