PHP highlight_string()ฟังก์ชั่น
ตัวอย่าง
ส่งออกสตริงโดยเน้นไวยากรณ์ PHP:
<html>
<body>
<?php
highlight_string("Hello world! <?php phpinfo(); ?>");
?>
</body>
</html>
ผลลัพธ์ของเบราว์เซอร์ของโค้ดด้านบนจะเป็น:
Hello world! <?php phpinfo(); ?>
เอาต์พุต HTML ของโค้ดด้านบนจะเป็น (View Source):
<html>
<body>
<code>
<span style="color: #000000">Hello world!
<span style="color: #0000BB"><?php phpinfo</span>
<span style="color: #007700">(); </span>
<span style="color: #0000BB">?></span>
</span>
</code>
</body>
</html>
ความหมายและการใช้งาน
ฟังก์ชัน highlight_string() จะแสดงผลสตริงโดยเน้นที่ไวยากรณ์ PHP สตริงถูกเน้นโดยใช้แท็ก HTML
สีที่ใช้สำหรับการเน้นไวยากรณ์สามารถตั้งค่าได้ในไฟล์ php.ini หรือด้วยฟังก์ชัน ini_set()
ไวยากรณ์
highlight_string(string,return)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
string | Required. Specifies the string to be highlighted |
return | Optional. If set to TRUE, this function will return the highlighted code as a string, instead of printing it out. Default is FALSE |
รายละเอียดทางเทคนิค
คืนมูลค่า: | ส่งกลับ TRUE เมื่อสำเร็จ หรือ FALSE เมื่อล้มเหลว |
---|---|
รุ่น PHP: | 4+ |
บันทึกการเปลี่ยนแปลง: | เพิ่มพารามิเตอร์ส่งคืน ใน PHP 4.2.0 |
❮ PHP การอ้างอิงเบ็ดเตล็ด