โค้ด: เลือกทั้งหมด
<?php
$test = "A B C D";
$arr = explode (' ',$test);
print_r($arr);
?>
ผลลัพธ์ : Array ( [0] => A [1] => B [2] => C [3] => D )
โค้ด: เลือกทั้งหมด
<?php
$arr = array('A' , 'B' , 'C' , 'D');
$test = implode (' ',$arr);
echo $test;
?>
ผลลัพธ์ : A B C D
โค้ด: เลือกทั้งหมด
<?php
$num = "12345";
echo number_format($num,2,'.',',');
?>
ผลลัพธ์ : 12,345.00
โค้ด: เลือกทั้งหมด
<?php
$test = "Hello World<br/>";
echo str_repeat($test,5);
?>
ผลลัพธ์ :
Hello World
Hello World
Hello World
โค้ด: เลือกทั้งหมด
<?php
$test = "Hello World";
echo substr($test,2,7);
?>
ผลลัพธ์ : llo Wor
โค้ด: เลือกทั้งหมด
<?php
$test = "Hello World";
echo strlen($test);
?>
ผลลัพธ์ : 11
โค้ด: เลือกทั้งหมด
<?php
$test = "Hello World";
echo strpos($test,'World');
?>
ผลลัพธ์ : 6 //นับจำนวนของคำที่เหลือ
VDO สอนเขียน PHP7
ที่มาของข้อมูล : ใช้งาน Built-in functions เกี่ยวกับ String