ฟังก์ชั่น php ที่หาตั้งนาน
หลังจากนั่งนึกหาฟังก์ชั่น ฟังก์ชั่นนึงนานมาก เพื่อจะแก้ปัญหาที่ต้องการ
นึกเท่าไหร่ก็นึกไม่ออก ลองเปิดหนังสือก็ไม่เจอ อาจจะเพราะฟังก์ชั่นนี้ไม่ค่อยได้ใช้เท่าไหร่

ฟังก์ชั่นที่พูดถึงคือ substr_count()
เป็นฟังก์ชั่นที่ใช้นับจำนวนคำในข้อความ ว่ามีทั้งหมดกี่ครั้ง

วิธีใช้ง่ายๆ คือ
$text 'This is a test';
echo 
strlen($text); // 14

echo substr_count($text'is'); // 2

// the string is reduced to 's is a test', so it prints 1
echo substr_count($text'is'3);

// the text is reduced to 's i', so it prints 0
echo substr_count($text'is'33);

// generates a warning because 5+10 > 14
echo substr_count($text'is'510);


// prints only 1, because it doesn't count overlapped substrings
$text2 'gcdgcdgcd';
echo 
substr_count($text2'gcdgcd');
?>



Create Date : 11 เมษายน 2555
Last Update : 11 เมษายน 2555 11:50:38 น.
Counter : 654 Pageviews.

0 comments
ชื่อ : * blog นี้ comment ได้เฉพาะสมาชิก
Comment :
 *ส่วน comment ไม่สามารถใช้ javascript และ style sheet
 

สี่ผู้คุมกฎราชสีห์ฝอยทอง
Location :
  

[ดู Profile ทั้งหมด]
 ฝากข้อความหลังไมค์
 Rss Feed
 Smember
 ผู้ติดตามบล็อก : 1 คน [?]



เมษายน 2555

1
2
3
4
5
6
7
8
9
10
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30