fnmatch

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

fnmatchMatch filename against a pattern

Beschreibung

fnmatch(string $pattern, string $filename, int $flags = 0): bool

fnmatch() checks if the passed filename would match the given shell wildcard pattern.

Parameter-Liste

pattern

The shell wildcard pattern.

filename

The tested string. This function is especially useful for filenames, but may also be used on regular strings.

The average user may be used to shell patterns or at least in their simplest form to '?' and '*' wildcards so using fnmatch() instead of preg_match() for frontend search expression input may be way more convenient for non-programming users.

flags

The value of flags can be any combination of the following flags, joined with the binary OR (|) operator.

A list of possible flags for fnmatch()
Flag Description
FNM_NOESCAPE Disable backslash escaping.
FNM_PATHNAME Slash in string only matches slash in the given pattern.
FNM_PERIOD Leading period in string must be exactly matched by period in the given pattern.
FNM_CASEFOLD Caseless match. Part of the GNU extension.

Rückgabewerte

Returns true if there is a match, false otherwise.

Beispiele

Beispiel #1 Checking a color name against a shell wildcard pattern

<?php
if (fnmatch("*gr[ae]y"$color)) {
  echo 
"some form of gray ...";
}
?>

Anmerkungen

Warnung

For now, this function is not available on non-POSIX compliant systems except Windows.

Siehe auch

  • glob() - Findet Dateinamen, die mit einem Muster übereinstimmen
  • preg_match() - Führt eine Suche mit einem regulären Ausdruck durch
  • sscanf() - Überträgt einen String in ein angegebenes Format
  • printf() - Liefert einen formatierten String
  • sprintf() - Gibt einen formatierten String zurück

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

How Clean SQL Architecture Saves You From Technical Debt

Once I realized I could offload repeat logic to SQL views, my PHP Infinite Craft​ (https://infinitecraftrecipes.io) code started looking more li ...

Geschrieben von bekeanloinse56 am 20.05.2025 05:16:28
Forum: SQL / Datenbanken
Hilfe! Datenübertragung

genau wie Flavaslava schon gesagt hat: Du brauchst eine .php-Datei, die dein Formular ausliest und dann die Verbindung zur MySQL-Datenbank herstel ...

Geschrieben von bekeanloinse56 am 20.05.2025 05:13:57
Forum: SQL / Datenbanken
How Clean SQL Architecture Saves You From Technical Debt

Poor SQL structure leads to long-term pain. Without proper keys, normalization, or naming, everything downstream becomes harder to maintain and sc ...

Geschrieben von jenniekimberly am 20.05.2025 04:39:36
Forum: SQL / Datenbanken
Problem: Benutzer wird nach erfolgreichem Steam-Login nicht als eingeloggt erkannt

Hier mal die Debug Ausgaben die gesetzt werden nach dem Versuchten Steam Login Datei: cookie_check.log { "_lcp": "a", "fusionuc223_ ...

Geschrieben von Drakikosa am 19.05.2025 21:20:04
Forum: PHP Developer Forum