mIRC Home    About    Download    Register    News    Help

Print Thread
#214694 12/08/09 02:35 PM
Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
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.


Newbie
HaleyJ #214697 12/08/09 04:41 PM
Joined: Dec 2008
Posts: 1,515
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
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.


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
HaleyJ #214703 13/08/09 12:27 AM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
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)


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
HaleyJ #214706 13/08/09 01:18 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
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

Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
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.


Newbie
HaleyJ #214712 13/08/09 01:50 PM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
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


Link Copied to Clipboard