Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

question on using strtok

Posted on 2003-11-28
2
Medium Priority
?
284 Views
Last Modified: 2010-05-18
hi all,

I found problem on using strtok in the following case (the first object is "0"), I found my string not to be tokenlize when the delimiter is :,;....
but it works when the delimiter is "\n"

<?php
$string = "0:1:2:3:4";
$tok = strtok($string,":");
while ($tok) {
    echo "Word=$tok<br>";
    $tok = strtok(":");
}
?>

how can I fix this?
0
Comment
Question by:esther_6694
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
_nn_ earned 200 total points
ID: 9837174
See http://www.php.net/manual/en/function.strtok.php

<quote>
Also be careful that your tokens may be equal to "0". This evaluates to FALSE in conditional expressions
</quote>

Use instead :

while ($tok !== false) {
0
 

Author Comment

by:esther_6694
ID: 9840664
thanks for your answer, this is the first time for me to use of the !== operator! Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question