PHP -Tutorial

PHP-HOME PHP-Einführung PHP-Installation PHP-Syntax PHP-Kommentare PHP-Variablen PHP-Echo / Drucken PHP-Datentypen PHP-Strings PHP-Nummern PHP-Mathematik PHP-Konstanten PHP-Operatoren PHP If...Else...Elseif PHP-Schalter PHP-Schleifen PHP-Funktionen PHP-Arrays PHP-Superglobals PHP-RegEx

PHP -Formulare

Handhabung von PHP-Formularen PHP-Formularvalidierung PHP-Formular erforderlich PHP-Formular-URL/E-Mail PHP-Formular vollständig

PHP- Erweitert

PHP-Datum und -Zeit PHP einschließen Umgang mit PHP-Dateien PHP-Datei öffnen/lesen PHP-Datei erstellen/schreiben Hochladen von PHP-Dateien PHP-Cookies PHP-Sitzungen PHP-Filter PHP-Filter für Fortgeschrittene PHP-Callback-Funktionen PHP-JSON PHP-Ausnahmen

PHP -OOP

PHP Was ist OOP PHP-Klassen/Objekte PHP-Konstruktor PHP-Destruktor PHP-Zugriffsmodifikatoren PHP-Vererbung PHP-Konstanten Abstrakte PHP-Klassen PHP-Schnittstellen PHP-Eigenschaften Statische PHP-Methoden Statische PHP-Eigenschaften PHP-Namespaces PHP-Iterables

MySQL- Datenbank

MySQL-Datenbank MySQL Connect MySQL-DB erstellen MySQL-Tabelle erstellen MySQL-Daten einfügen MySQL Letzte ID abrufen MySQL Mehrfach einfügen MySQL vorbereitet MySQL Select-Daten MySQL-Wo MySQL-Reihenfolge nach MySQL-Daten löschen MySQL-Update-Daten MySQL-Limit-Daten

PHP- XML

PHP-XML-Parser PHP-SimpleXML-Parser PHP SimpleXML - Get PHP-XML-Expat PHP-XML-DOM

PHP -AJAX

AJAX-Einführung AJAX-PHP AJAX-Datenbank AJAX-XML AJAX Live-Suche AJAX-Umfrage

PHP- Beispiele

PHP-Beispiele PHP-Compiler PHP-Quiz PHP-Übungen PHP-Zertifikat

PHP- Referenz

PHP-Übersicht PHP-Array PHP-Kalender PHP-Datum PHP-Verzeichnis PHP-Fehler PHP-Ausnahme PHP-Dateisystem PHP-Filter PHP-FTP PHP-JSON PHP-Schlüsselwörter PHP-Libxml PHP-Mail PHP-Mathematik PHP-Sonstiges PHP MySQLi PHP-Netzwerk PHP-Ausgabesteuerung PHP-RegEx PHP-SimpleXML PHP-Stream PHP-String Umgang mit PHP-Variablen PHP-XML-Parser PHP-Zip PHP-Zeitzonen

PHP - Funktion money_format()

❮ PHP-String-Referenz

Beispiel

Internationales en_US-Format:

<?php
$number = 1234.56;
setlocale(LC_MONETARY,"en_US");
echo money_format("The price is %i", $number);
?>

Die Ausgabe des obigen Codes lautet:

The price is USD 1,234.56


Definition und Verwendung

Die Funktion money_format() gibt eine Zeichenfolge zurück, die als Währungszeichenfolge formatiert ist.

Diese Funktion fügt eine formatierte Zahl dort ein, wo ein Prozentzeichen (%) in der Hauptzeichenfolge vorhanden ist.

Hinweis: Die Funktion money_format() funktioniert nicht auf Windows-Plattformen.

Tipp: Diese Funktion wird oft zusammen mit der Funktion setlocale() verwendet.

Tipp: Um alle verfügbaren Sprachcodes anzuzeigen, gehen Sie zu unserer Sprachcode-Referenz.


Syntax

money_format(string,number)

Parameterwerte

Parameter Description
string Required. Specifies the string to be formatted and how to format the variables in it.

Possible format values:

Padding and Flags:

  • =f - Specifies the character (f) to be used as padding (Example: %=t this uses "t" as padding). Default is space
  • ^ - Removes the use of grouping characters
  • + or ( - Specifies how to show positive and negative numbers. If "+" is used, the local setting for + and - will be used (usually a sign in front of negative numbers, and nothing in front of positive numbers). If "(" is used, negative numbers are enclosed in parenthesis. Default is "+"
  • ! - Stops the use of currency symbols in the output string
  • - If "-" is used, all fields are left-justified. Default is right-justified

Field width:

  • x - Specifies the minimum field width (x). Default is 0
  • #x - Specifies the maximum number (x) of digits expected to the left of the decimal point. This is used to keep formatted output aligned in the same columns. If the number of digits are bigger than x, this specification is ignored
  • .x - Specifies the maximum number (x) of digits expected to the right of the decimal point. If x is 0, the decimal point and the digits to its right will not be shown. Default is local settings

Conversion characters:

  • i - The number is formatted to international currency format
  • n - The number is formatted to national currency format
  • % - Returns the % character

Note: If multiple format values are used, they must be in the same order as shown above.

Note: This function is affected by local settings.

number Required. The number to be inserted at the %-sign in the format string


Technische Details

Rückgabewert: Gibt die formatierte Zeichenfolge zurück. Zeichen vor und nach der Formatierungszeichenfolge werden unverändert zurückgegeben. Eine nicht numerische Zahl bewirkt, dass NULL zurückgegeben und E_WARNING ausgegeben wird
PHP-Version: 4.3.0+

Mehr Beispiele

Beispiel

Internationales Format (Deutschland) mit 2 Dezimalstellen:

<?php
$number = 1234.56;
setlocale(LC_MONETARY,"de_DE");
echo money_format("%.2n", $number);
?>

Die Ausgabe des obigen Codes lautet:

1 234,56 EUR

Beispiel

Negative Zahl, nationales US-Format mit () zur Angabe negativer Zahlen und 2 Ziffern mit richtiger Genauigkeit und "*" als Füllzeichen:

<?php
$number = -1234.5672;
echo money_format("%=*(#10.2n",$number);
?>

Die Ausgabe des obigen Codes lautet:

(******1234.57)


❮ PHP-String-Referenz