loclan Posted April 4, 2006 Share Posted April 4, 2006 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... [b][i]MY QUESTION: let's say, the current $my_token is now "string". How do I check if the previous $my_token is actually "test"?[/i][/b]$my_token = strtok(" ");}I know, I could have used the "for loop" to make things simpler - but I didn't ;-)Thank you. Link to comment https://forums.phpfreaks.com/topic/6568-how-do-you-go-to-previousnext-token/ Share on other sites More sharing options...
trq Posted April 4, 2006 Share Posted April 4, 2006 Maybe...?[code]$i = 0;while ($my_token) { $tmp[$i] = $my_token; if ($my_token == 'string') { $previous = $tmp[$i-1]; } $i++;}[/code]A bit messy but hey... Link to comment https://forums.phpfreaks.com/topic/6568-how-do-you-go-to-previousnext-token/#findComment-23837 Share on other sites More sharing options...
loclan Posted April 4, 2006 Author Share Posted April 4, 2006 [!--quoteo(post=361588:date=Apr 4 2006, 11:00 AM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Apr 4 2006, 11:00 AM) [snapback]361588[/snapback][/div][div class=\'quotemain\'][!--quotec--]Maybe...?[code]$i = 0;while ($my_token) { $tmp[$i] = $my_token; if ($my_token == 'string') { $previous = $tmp[$i-1]; } $i++;}[/code]A bit messy but hey...[/quote]Hmm... yeah, that should work - messy, but should work. If anyone knows a cleaner solution, much appreciated. Link to comment https://forums.phpfreaks.com/topic/6568-how-do-you-go-to-previousnext-token/#findComment-23839 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.