Jump to content


Photo

How do you go to previous/next token?


  • Please log in to reply
2 replies to this topic

#1 loclan

loclan
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 April 2006 - 02:57 PM

Ok, this has stumped me for the day (and the day has just started):

$my_string = "This is a test string";
$my_token = strtok ($my_string, " ");

while ($my_token) {
do something...

MY QUESTION: let's say, the current $my_token is
now "string". How do I check if the previous $my_token
is actually "test"?


$my_token = strtok(" ");
}

I know, I could have used the "for loop" to make things simpler - but I didn't ;-)

Thank you.

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 April 2006 - 04:00 PM

Maybe...?
$i = 0;
while ($my_token) {
  $tmp[$i] = $my_token;
  if ($my_token == 'string') {
    $previous = $tmp[$i-1];
  }
  $i++;
}
A bit messy but hey...

#3 loclan

loclan
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 April 2006 - 04:04 PM

[!--quoteo(post=361588:date=Apr 4 2006, 11:00 AM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Apr 4 2006, 11:00 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Maybe...?
$i = 0;
while ($my_token) {
  $tmp[$i] = $my_token;
  if ($my_token == 'string') {
    $previous = $tmp[$i-1];
  }
  $i++;
}
A bit messy but hey...
[/quote]

Hmm... yeah, that should work - messy, but should work. If anyone knows a cleaner solution, much appreciated.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users