บทช่วยสอนPHP

PHP HOME แนะนำ PHP การติดตั้ง PHP PHP ไวยากรณ์ ความคิดเห็น PHP ตัวแปร PHP PHP Echo / พิมพ์ ประเภทข้อมูล PHP PHP Strings หมายเลข PHP PHP คณิตศาสตร์ ค่าคงที่ PHP ตัวดำเนินการ PHP PHP If...Else...Elseif PHP Switch PHP Loops ฟังก์ชัน PHP PHP Arrays PHP Superglobals PHP RegEx

แบบฟอร์มPHP

การจัดการแบบฟอร์ม PHP การตรวจสอบแบบฟอร์ม PHP ต้องใช้แบบฟอร์ม PHP URL แบบฟอร์ม PHP/อีเมล แบบฟอร์ม PHP เสร็จสมบูรณ์

PHPขั้นสูง

วันที่และเวลา PHP รวม PHP การจัดการไฟล์ PHP ไฟล์ PHP เปิด/อ่าน สร้าง/เขียนไฟล์ PHP อัพโหลดไฟล์ PHP คุกกี้ PHP PHP Sessions ตัวกรอง PHP ตัวกรอง PHP ขั้นสูง ฟังก์ชันเรียกกลับของ PHP PHP JSON ข้อยกเว้น PHP

PHP OOP

PHP OOP คืออะไร คลาส PHP/วัตถุ ตัวสร้าง PHP PHP Destructor PHP Access Modifiers PHP Inheritance ค่าคงที่ PHP PHP Abstract Classes อินเทอร์เฟซ PHP PHP ลักษณะ PHP Static Methods PHP คุณสมบัติคงที่ PHP เนมสเปซ PHP Iterables

ฐานข้อมูลMySQL

ฐานข้อมูล MySQL MySQL Connect MySQL สร้าง DB MySQL สร้างตาราง MySQL แทรกข้อมูล MySQL รับ ID ล่าสุด MySQL แทรกหลายรายการ MySQL ที่เตรียมไว้ MySQL Select Data MySQL Where MySQL สั่งซื้อโดย MySQL ลบข้อมูล ข้อมูลอัพเดต MySQL MySQL Limit Data

PHP XML

PHP XML Parsers PHP SimpleXML Parser PHP SimpleXML - รับ PHP XML Expat PHP XML DOM

PHP - AJAX

บทนำ AJAX AJAX PHP ฐานข้อมูล AJAX AJAX XML AJAX ค้นหาสด AJAX โพล

ตัวอย่างPHP

ตัวอย่าง PHP PHP คอมไพเลอร์ แบบทดสอบ PHP แบบฝึกหัด PHP ใบรับรอง PHP

ข้อมูลอ้างอิงPHP

ภาพรวม PHP PHP Array ปฏิทิน PHP PHP วันที่ ไดเรกทอรี PHP ข้อผิดพลาด PHP ข้อยกเว้น PHP ระบบไฟล์ PHP ตัวกรอง PHP PHP FTP PHP JSON คีย์เวิร์ด PHP PHP Libxml PHP Mail PHP คณิตศาสตร์ PHP เบ็ดเตล็ด PHP MySQLi เครือข่าย PHP การควบคุมเอาต์พุต PHP PHP RegEx PHP SimpleXML PHP Stream PHP String
addcslashes() เครื่องหมายทับ () bin2hex() สับ() chr() chunk_split() Convert_cyr_string() convert_uudecode() Convert_uuencode() count_chars() crc32() ห้องใต้ดิน() เสียงสะท้อน() ระเบิด() พิมพ์ () get_html_translation_table() ฮีบรู () ภาษาฮีบรูฟ () hex2bin() html_entity_decode() htmlentities() htmlspecialchars_decode() htmlspecialchars() ระเบิด() เข้าร่วม() lcfirst() เลเวนชไทน์() localeconv() ลทริม () md5() md5_file() เมตาโฟน() money_format() nl_langinfo () nl2br() number_format() คำ() parse_str() พิมพ์() พิมพ์f() quoted_printable_decode() quoted_printable_encode() ข้อมูลอ้างอิง () อาร์ทริม() setlocale() sha1() sha1_file() คล้ายกัน_text() ซาวด์เอ็กซ์() sprintf() sscanf() str_getcsv () str_ireplace () str_pad() str_repeat() str_replace() str_rot13 () str_shuffle() str_split () str_word_count() strcasecmp() strchr() strcmp() strcoll() strcspn() strip_tags() แถบสแลช() แถบสแลช() การ์ตูน () แถบ () strlen() strnatcasecmp() strnatcmp() strncasecmp() strncmp() strpbrk () สตรอปส์() strchr() strrev () สตริพอส() สตริพอส() strspn () strstr() strtok() strtolower() สตรอปเปอร์() strtr() ย่อย () substr_compare() substr_count() substr_replace() ตัดแต่ง() ucfirst() ucwords() vfprintf() vprintf() vsprintf() ตัดคำ()
การจัดการตัวแปร PHP PHP XML Parser PHP Zip เขตเวลา PHP

PHP money_format()ฟังก์ชัน

❮ การอ้างอิงสตริง PHP

ตัวอย่าง

รูปแบบ en_US ระหว่างประเทศ:

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

ผลลัพธ์ของโค้ดด้านบนจะเป็น:

The price is USD 1,234.56


ความหมายและการใช้งาน

ฟังก์ชัน money_format() ส่งคืนสตริงที่จัดรูปแบบเป็นสตริงสกุลเงิน

ฟังก์ชันนี้จะแทรกตัวเลขที่จัดรูปแบบแล้วซึ่งมีเครื่องหมายเปอร์เซ็นต์ (%) ในสตริงหลัก

หมายเหตุ:ฟังก์ชัน money_format() ไม่ทำงานบนแพลตฟอร์ม Windows

เคล็ดลับ:ฟังก์ชันนี้มักใช้ร่วมกับ ฟังก์ชันsetlocale()

เคล็ดลับ:หากต้องการดูรหัสภาษาที่มีทั้งหมด ให้ไปที่การอ้างอิงรหัสภาษา ของเรา


ไวยากรณ์

money_format(string,number)

ค่าพารามิเตอร์

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


รายละเอียดทางเทคนิค

คืนมูลค่า: ส่งกลับสตริงที่จัดรูปแบบ อักขระก่อนและหลังสตริงการจัดรูปแบบจะถูกส่งกลับไม่เปลี่ยนแปลง ตัวเลขที่ไม่ใช่ตัวเลขทำให้เกิดค่า NULL และเปล่ง E_WARNING
รุ่น PHP: 4.3.0+

ตัวอย่างเพิ่มเติม

ตัวอย่าง

รูปแบบสากล (เยอรมนี) ที่มีทศนิยม 2 ตำแหน่ง:

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

ผลลัพธ์ของโค้ดด้านบนจะเป็น:

1 234,56 EUR

ตัวอย่าง

ตัวเลขติดลบ รูปแบบแห่งชาติของสหรัฐอเมริกาด้วย () เพื่อระบุตัวเลขติดลบและความแม่นยำที่ถูกต้อง 2 หลัก และ "*" เป็นอักขระเติม:

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

ผลลัพธ์ของโค้ดด้านบนจะเป็น:

(******1234.57)


❮ การอ้างอิงสตริง PHP