<?php $contents = 'F1 dddff F1 ffcc F1'; //นับจำนวน คำว่า F1 $c = substr_count($contents,'F1'); echo "count 'F1' in contents = $c"; //count 'F1' in contents = 3 ?>
<?php $string = 'Banana'; for ( $i = 0; $i < strlen($string); $i++ ) { $count = -1; $text = $string[$i]; for ( $x = 0; $x < strlen($string); $x++ ) { if ( $text == $string[$x] ) { $count++; } } if ( $count > 1 ) { echo 'String ' .$text . ' มีตัวซ้ำทั้งหมด ' . ($count + 1) . '<br />'; } else { echo 'String ' .$text . ' ไม่มีตัวซ้ำ <br />'; } } ?>
<?php $string = 'Banana'; $stringAdd = array(); for ( $i = 0; $i < strlen($string); $i++ ) { $count = -1; $text = $string[$i]; for ( $x = 0; $x < strlen($string); $x++ ) { if ( $text == $string[$x] ) { $count++; } } if ( $count > 1 && ! in_array($text, $stringAdd) ) { $stringAdd[] = $text; echo 'String ' .$text . ' มีตัวซ้ำทั้งหมด ' . ($count + 1) . '<br />'; } elseif ( ! in_array($text, $stringAdd) ) { $stringAdd[] = $text; echo 'String ' .$text . ' ไม่มีตัวซ้ำ <br />'; } } ?>
<?php /** * @author Marosdee * @copyright 2009 */ $string = 'Banana'; $stringAdd = array(); for ( $i = 0; $i < strlen($string); $i++ ) { $count = 0; $text = $string[$i]; for ( $x = 0; $x < strlen($string); $x++ ) { if ( $text == $string[$x] ) { $count++; } } if ( $count > 1 && ! in_array($text, $stringAdd) ) { $stringAdd[] = $text; echo 'String ' .$text . ' มีตัวซ้ำทั้งหมด ' . ($count) . '<br />'; } elseif ( ! in_array($text, $stringAdd) ) { $stringAdd[] = $text; echo 'String ' .$text . ' ไม่มีตัวซ้ำ <br />'; } } ?>
<?php $string = "Banana"; $splited = str_split($string); print_r(array_count_values($splited)); ?>
<form action="countstr.php" method="post"> Input String : <input type="text" name="str"> </form>
$String = $_POST['str']
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง