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()
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…
-
WordPress: how to remove the ‘link rel=shortlink’ tag from your site
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…
-
How to delete a single element from an array in PHP
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…
-
PHP fatal error: Uncaught TypeError: ftp_nlist(): Argument #1 ($ftp) must be of type FTP\Connection, null given
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…
-
PHP: when to use ‘self’ and when to use ‘$this’?
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…
-
PHP: How to check if a string contains a specific word?
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…
-
Pecl: fixing “fatal error: ‘pcre2.h’ file not found”
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…
-
PHP: Function utf8_decode() and utf8_encode() have been deprecated
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…
-
Wo ist meine php.ini?
Wo die aktuell verwendete php.ini gespeichert ist, lässt sich ganz einfach über phpinfo() ermitteln. Dazu einfach eine neue php-Datei im Web-Verzeichnis speichern und mit folgendem Inhalt füllen: Wird diese Datei über den Browser aufgerufen, dann ist aus der Ausgabe der Funktion phpinfo() ersichtlich, welche php.ini gerade verwendet wird: Die wichtigen Punkte sind hierbei Loaded Configuration…
-
PHP: rounding a number and keeping the zeros after comma
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…
-
PHP: get version details from composer.json
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…
-
Simple Optimization for PHP and MySQL
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
-
PHP: realpath() for non-existing path
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:
-
How to ignore PHP_CodeSniffer warning: Line exceeds 120 characters
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:…
-
PNG – deactivate interlace to avoid ‘libpng warning: Interlace handling should be turned on when using png_read_image’
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…
-
PHP ColorUtils
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…
-
PHP: Wie bekommt man Gettext zum Laufen?
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…
-
MacPorts: mehrere PHP-Versionen gleichzeitig
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,…
-
Composer global verwenden
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…
-
Imagick und “libgomp: Thread creation failed: Resource temporarily unavailable”
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…