Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

question on using strtok

Posted on 2003-11-28
2
Medium Priority
?
285 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 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

885 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