Dividing a String into Tokens with strtok() : strtok « String « PHP






Dividing a String into Tokens with strtok()

 
<?php
<html>
<head>
<title>Dividing a string into tokens with strtok()</title>
</head>
<body>
<div>
<?php
$test = "php?id=353&sec=44&user=harry&context=php";

$delims = "?&";
$word = strtok( $test, $delims );
while ( is_string( $word ) ) {
 if ( $word ) {
   print "$word<br/>";
 }
 $word = strtok( $delims );
}
?>
</div>
</body>
</html>
  
  








Related examples in the same category

1.strtok() function performs a similar task to explode()
2.strtok() function tokenizes string, using the characters specified in tokens.
3.strtok.php