Tag: PHP

PHP (recursive acronym: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language. PHP is especially suited for web development. It allows developers to create dynamic web pages by embedding the code into HTML.

  • Fatal error: Call to undefined function bindtextdomain()

    Fatal error: Call to undefined function bindtextdomain()

    By

    in

    This error might be caused by a missing GetText extension. GetText is a widely-used internationalization and localization (i18n/l10n) system that provides tools for translating software messages into different languages. To solve the error, you have to enable the extension in your php.ini. For this, open your php.ini and uncomment (or add) the following line: If…

    Read more

  • WordPress: how to remove the ‘link rel=shortlink’ tag from your site

    WordPress: how to remove the ‘link rel=shortlink’ tag from your site

    By

    in ,

    By default, WordPress adds <link rel=”shortlink”> meta tag to the <head> of a website and uses the short url like https://mixable.blog/?p=4803 for this. When you already use nice slugs as permalink structure, such a tag is not necessary, because you already have unique urls. To remove the shortlink tag, you can use an additional plugin…

    Read more

  • How to delete a single element from an array in PHP

    How to delete a single element from an array in PHP

    By

    in

    PHP already provides a large number of methods to manipulate arrays. The official PHP documentation shows a full list of array functions. Those can be used to create, sort and edit any of your arrays. Let’s assume you want to remove an item from an array. PHP provides multiple solutions out of the box. Let’s…

    Read more

  • PHP fatal error: Uncaught TypeError: ftp_nlist(): Argument #1 ($ftp) must be of type FTP\Connection, null given

    PHP fatal error: Uncaught TypeError: ftp_nlist(): Argument #1 ($ftp) must be of type FTP\Connection, null given

    By

    in ,

    After moving a WordPress installation to another server, the following error showed up: The new server had a different linux distribution and a newer PHP version. In my case, the environment changed from PHP 7.4 to PHP 8.2. I already added some missing PHP extensions and updated the configuration to match the old one, but…

    Read more

  • PHP: when to use ‘self’ and when to use ‘$this’?

    PHP: when to use ‘self’ and when to use ‘$this’?

    By

    in

    In PHP, the term $this is utilized to point to the current instance of the class whereas the term self is used to indicate the class itself. Its recommended to use $this when referring to instance level properties or methods within the class, like accessing a property of the object or invoking a method of…

    Read more

  • PHP: How to check if a string contains a specific word?

    PHP: How to check if a string contains a specific word?

    By

    in

    When working with strings in PHP, you can already use many useful functions to manipulate the string contents. However, sometimes you only want to check for the string contents before performing an action. In PHP you can determine if a string includes a word by utilizing functions like strpos(), preg_match() or str_contains(). Using strpos() The…

    Read more

  • Pecl: fixing “fatal error: ‘pcre2.h’ file not found”

    Pecl: fixing “fatal error: ‘pcre2.h’ file not found”

    By

    in

    When using pecl to install a PHP extension, I always got a “fatal error: ‘pcre2.h’ file not found” after PHP has been updated. The update was done using brew upgrade php. In my case, this happens when I try to install pcov using: The output was: To fix the issue, make sure you have pcre2…

    Read more

  • PHP: Function utf8_decode() and utf8_encode() have been deprecated

    PHP: Function utf8_decode() and utf8_encode() have been deprecated

    By

    in

    The utf8_encode() and utf8_decode() functions in PHP are used for encoding and decoding strings between ISO-8859-1 (Latin-1) encoding and UTF-8 encoding. While PHP’s standard library does include utf8_encode and utf8_decode functions, they are limited to converting between ISO-8859-1 (Latin-1) and UTF-8 encodings. It is important to note that these functions cannot be relied upon to…

    Read more

  • PHP: rounding a number and keeping the zeros after comma

    PHP: rounding a number and keeping the zeros after comma

    By

    in

    In PHP you can use the round() method to round a double. This methods accepts a precision value as second parameter. Some examples: When using round() on a value like 3.0000 the conversion to a string will result in just “3”: This is not wrong, but when you want to have a constant precision for…

    Read more

  • PHP: get version details from composer.json

    PHP: get version details from composer.json

    By

    in

    Composer is a tool for dependency management in PHP. It allows PHP developers to easily manage and install the libraries and packages their projects depend on. Composer simplifies the process of including external libraries into PHP projects and helps manage versioning and dependencies. The packages that are required for your project are located in a…

    Read more

  • Simple Optimization for PHP and MySQL

    Simple Optimization for PHP and MySQL

    By

    in

    Here is a list of a few very simple tips for optimizing your PHP and MySQL applications. Keep these in mind while developing. MySQL PHP Picture by SpaceX on Unsplash

    Read more

  • PHP: realpath() for non-existing path

    By

    in

    The php method realpath() can transform the string format of a path into a real path. Means, a path string like: will become: But this only works, if the path really exists. For non-existing paths, this function cannot be used. To get the same functionality, the following function can be used:

    Read more

  • How to ignore PHP_CodeSniffer warning: Line exceeds 120 characters

    How to ignore PHP_CodeSniffer warning: Line exceeds 120 characters

    By

    in

    PHP_CodeSniffer is a set of PHP scripts to detect violations of a defined coding standard, and to automatically correct such coding standard violations. When using CodeSniffer to check your code, a lot of warnings might appear for such violations. Accodring to PSR-2 coding style guide, a warning is raised when the lines are too long:…

    Read more

  • PNG – deactivate interlace to avoid ‘libpng warning: Interlace handling should be turned on when using png_read_image’

    PNG – deactivate interlace to avoid ‘libpng warning: Interlace handling should be turned on when using png_read_image’

    By

    in

    I stumbled appon a warning message that was thrown by PHP when handling images with GD lib (e.g. imagecreatefrompng()). The message shown was: This message even exists, when deactivating ‘interlace’ with the help of: The point is that this message is not caused by any wrong php code, it is caused by the processed images…

    Read more

  • PHP ColorUtils

    PHP ColorUtils

    By

    in

    A neat collection of useful methods to convert colors between different color spaces is available on GitHub call ColorConverter (MIT License). It can convert any values between RGB, HSL, CMYK, YUV and HEX colors. I created a ready-to-use php class out of this method collection: https://github.com/mixable/color-utils Usage The methods itself are mostly self-explaining. To use…

    Read more

  • PHP: Wie bekommt man Gettext zum Laufen?

    By

    in

    GNU gettext ist eine GNU-Programmbibliothek zur Internationalisierung von Software. Normalerweise wird sie zur Entwicklung von mehrsprachigen Programmen genutzt. Um diese in PHP zu nutzen, sind einige Informationen über die zu verwendende Sprache und der Speicherort der Sprachpakete notwendig. Dieser Artikel gibt eine kurze Beschreibung, wie man diese einrichten kann. Zunächst erstellt man sich ein Verzeichnis, z.B. locales/, in dem die…

    Read more

  • MacPorts: mehrere PHP-Versionen gleichzeitig

    By

    in

    MacPorts unterstützt jegliche PHP-Versionen. Diese können auch ohne Probleme gleichzeitig installiert werden. Die Pakete werden in MacPorts unter php56, php70, php71, … usw. gelistet. Die notwendigen Befehle, um eine einzelne Version zu installieren: MacPorts aktualisieren: PHP Version (beispielsweise PHP 7.0) und ggf. erforderliche Module installieren: Nun zum Aktivieren der gewünschten PHP-Version: hier muss beachtet werden,…

    Read more

  • Composer global verwenden

    Composer global verwenden

    By

    in

    In der Dokumentation zu Composer wird erläutert, wie man global auf composer.phar zugreifen kann, ohne permanent php composer.phar ins Terminal eingeben zu müssen: […] You can place the Composer PHAR anywhere you wish. If you put it in a directory that is part of your PATH, you can access it globally. On unix systems you…

    Read more

  • Imagick und “libgomp: Thread creation failed: Resource temporarily unavailable”

    By

    in

    Bei der Bildbearbeitung mit Imagick (PHP) kann es mitunter zu einem Timeout bzw. Internal Server Error kommen und die Grafik wird nicht erstellt. In meinem Fall immer dann, wenn man versucht einen Text in der Grafik mittels Imagick::annotateImage() darzustellen. Schaut man sich die error.log des Webservers an, dann stolpert man über den Fehler “libgomp: Thread…

    Read more

  • Apache2, PHP und MySQL über MacPorts installieren

    By

    in , ,

    Es gibt hier im Blog bereits eine Vielzahl an Posts zu diesem Thema. Warum? Mit jedem Update von Mac OS X scheint sich wieder etwas zu ändern, sodass die Installation von Apache / PHP / MySQL mittels MacPorts nicht mehr funktionieren möchte. Was bei den einzelnen OS X Versionen zu beachten ist, ist in den…

    Read more