ฟังก์ชัน ucwords ใน PHP

ucwords เป็นฟังก์ชันที่ทำหน้าที่ในการเปลี่ยนอักษรตัวแรกของคำให้เป็นตัวพิมพ์ใหญ่ ซี่งผมจะใช้ในร่วมกับการเปลี่ยนแปลงของ title tag, description tag อยู่บ่อยๆ เพื่อนๆ จะนำวิธีนี้ไปใช้ก็ไม่ว่านะครับ

รูปแบบการใช้งาน

string ucwords ( string $str )

ตัวอย่างการใช้งาน

<?php
$foo = 'helloworld!';
$foo = ucwords($foo); //HelloWorld!

$bar = 'HELLOWORLD!';
$bar = ucwords($bar); //HELLOWORLD!
$bar = ucwords(strtolower($bar)); //HelloWorld!
?>

ไม่รู้ว่าเมื่อเอามาใช้กับาษาไทยแล้วมันจะได้ผลยังไงนะครับ ^^ เพราะาษาไทยของเราไม่มีการแบ่งตัวพิมพ์เล็กพิมพ์ใหญ่

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>