Solved

question on using strtok

Posted on 2003-11-28
2
278 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
2 Comments
 
LVL 16

Accepted Solution

by:
_nn_ earned 50 total points
Comment Utility
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
Comment Utility
thanks for your answer, this is the first time for me to use of the !== operator! Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now