Solved

question on using strtok

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

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…
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 …

738 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