mIRC Homepage
Posted By: HaleyJ gettok in PHP - 12/08/09 02:35 PM
Hi everyone,

I know that this may be the wrong place to ask this. But I have scoured the Internet and not found a satisfiable solution - hence I have come here to seek help to port mIRC's gettok function (EXACTLY) over to PHP.

mIRC has made the job of parsing strings very easy with this function and I am hoping somebody here will be skilled enough to do code the precise function over to PHP.

I know that this is strictly a mIRC scripting forum but I am also aware that many talented scripters frequent this forum and I post here in the hope that one of them can help me.

Kindest, Regards.
Posted By: westor Re: gettok in PHP - 12/08/09 04:41 PM
I search a bit about this and found something , i don't know if its very helpful but check here or have a look in this link maybe you find that you want.
Posted By: argv0 Re: gettok in PHP - 13/08/09 12:27 AM
mIRC's gettok function basically wraps the C++ strtok function-- PHP also has a similar wrapper aptly named strtok(). The only difference is that //echo -a $gettok(a b c, 2, 32) would be equivalent to:

Code:
$x = strtok("a b c", " ");
$y = strtok(" ");
echo $y;


(You have to call strtok(" ") to get each subsequent token. You can wrap this in a gettok-style function though)
Posted By: genius_at_work Re: gettok in PHP - 13/08/09 01:18 AM
You can also make a function that just explodes the string into an array, and then access the appropriate array value.

Php Code:


$mystring = "This is my string to test";
$myarray = explode(" ",$mystring);
$mytoken = $myarray[2];
echo $mytoken;

 


Keep in mind that php is 0-based, rather than 1-based like mIRC. The first token is 0, the second is 1, etc.

-genius_at_work
Posted By: HaleyJ Re: gettok in PHP - 13/08/09 09:43 AM
mIRC's gettok function is alot more flexible. I am aware of the strtok function and have done something similiar to geniusatworks function.

I was looking for an exact replica as the mIRC function inorder to make use of its flexibility. For example $gettok(%string,1-4,32)will grab tthe first four tokens of a string in ONE call without calling the PHP strtok function four times.

Is there anyway an exact replica of mIRC's gettok function can be coded in php?

Thanks for all the answers.
Posted By: genius_at_work Re: gettok in PHP - 13/08/09 01:50 PM
Of course an exact replica can be made in PHP. String functions are the most basic in a programming language. You won't accomplish it in 2 lines of code though. Khaled's token identifiers don't just magically figure out what the 1st to 4th tokens are and give them to you. There is likely a lot of math/comparisons/error checks built into the gettok routine in his code. You just have to figure out how to make it yourself. PHP has array functions that will allow you to make all of the token identifiers in mIRC, and it will probably be easier than in mIRC's core language.

http://ca.php.net/manual/en/book.array.php

The bottom line is: YES the token functions can be duplicated in PHP, and NO you probably won't get someone here to do it for you.

-genius_at_work
© mIRC Discussion Forums