Use while loop to control the strpos in PHP

Description

The following code shows how to use while loop to control the strpos.

Example


<?php/*from w  w  w . ja v a2  s . co m*/

$myString = "Hello, world!";
$pos = 0;
while ( ( $pos = strpos( $myString, "l", $pos ) ) !== false ) {
  echo "The letter 'l' was found at position: $pos<br/>";
  $pos++;
}

?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone