Solved

question on using strtok

Posted on 2003-11-28
2
279 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Undefined Index in HTML Form? 2 32
can windows 10 wamp send mail()? 3 35
Form not operating correctly. 1 23
Whether to use true/false, yes/no or 0/1 11 51
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

863 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

19 Experts available now in Live!

Get 1:1 Help Now