ฟังก์ชั่น strpos()
ความหมายของฟังก์ชั่นและการใช้งาน
การค้นหาข้อความจากหน้าไปหลัง จะคืนค่าตำแหน่งแรกที่พบหรือคืนค่า false ถ้าไม่พบ โดยคำนึงถึงตัวพิมพ์เล็กพิมพ์ใหญ่ ด้วยฟังก์ชั่น strpos()
รูปแบบการเขียน (Syntax)
mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )
ตัวอย่างที่ 1
<?php
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}
?>