SkulkrinBait
Morkin Admin
Haxx0rs == Suxx0rs! v4
Posts: 6,680
|
Post by SkulkrinBait on Aug 15, 2005 6:05:24 GMT
Thanks, I'll try that tonight! How would I get rid of leading/trailing spaces?
Is $needle defined anywhere?
I assume you say $needle = "Gold Mine " or something?
The task of doing this for each item in the spy report isn't too hard, when I've already coded the table with those variables and the input/output scripts too!
How's $answerlength come into this, where is it assigned?
|
|
SkulkrinBait
Morkin Admin
Haxx0rs == Suxx0rs! v4
Posts: 6,680
|
Post by SkulkrinBait on Aug 15, 2005 6:30:56 GMT
Couple of other coding questions!
Remind me how I call a function and pass the variables it wants, I've done this before but I've no example code I can get hold of right now.
Can the function code be inside the main code or a separate php file?
|
|
SkulkrinBait
Morkin Admin
Haxx0rs == Suxx0rs! v4
Posts: 6,680
|
Post by SkulkrinBait on Aug 15, 2005 6:38:03 GMT
It seems to work, need to test more thoroughly. I made one small amendment: $answer = substr($haystack, ($found_position+$needle_length), $answerlength); test code here: www.speedworx.org/ik/test.php
|
|
SkulkrinBait
Morkin Admin
Haxx0rs == Suxx0rs! v4
Posts: 6,680
|
Post by SkulkrinBait on Aug 15, 2005 7:07:30 GMT
Oh, thanks for the info by the way Robert.
|
|
soiram
Morkin Member
Morkin Godfather
Posts: 1,125
|
Post by soiram on Aug 15, 2005 9:49:52 GMT
I will be definitely using this when I get back. I tried logging in another record but I had an error message.
|
|
SkulkrinBait
Morkin Admin
Haxx0rs == Suxx0rs! v4
Posts: 6,680
|
Post by SkulkrinBait on Aug 15, 2005 10:24:54 GMT
What error?
|
|
SkulkrinBait
Morkin Admin
Haxx0rs == Suxx0rs! v4
Posts: 6,680
|
Post by SkulkrinBait on Aug 15, 2005 11:08:32 GMT
Oh yes, you would get an error, I was updating the code.
|
|
SkulkrinBait
Morkin Admin
Haxx0rs == Suxx0rs! v4
Posts: 6,680
|
Post by SkulkrinBait on Aug 15, 2005 11:49:17 GMT
I get this now:
"Fatal error: Call to undefined function: extractfromspyreport() in /home/qhwslos/public_html/ik/enter.php on line 82"
The code is:
Function extractfromspyreport($needle, $answerlength, $haystack) { $needle = "Gold Mine Level "; $answerlength = 2; $found_position = strpos($description, $needle); $needle_length = strlen($needle);
if($found_position AND $needle_length) { $answer = substr($description,(found_position+$needle_length),$answerlength); } else { $answer = "N/A"; } return $answer; }
So I don't get it, should the function be defined in a separate file or at the top of the code etc?
|
|
SkulkrinBait
Morkin Admin
Haxx0rs == Suxx0rs! v4
Posts: 6,680
|
Post by SkulkrinBait on Aug 15, 2005 11:54:28 GMT
It's OK I fixed it, I had called the function before I defined it, stupid computers!
|
|
|
Post by Old Shendemiar on Aug 15, 2005 14:13:10 GMT
Thanks, I'll try that tonight! How would I get rid of leading/trailing spaces? Is $needle defined anywhere? I assume you say $needle = "Gold Mine " or something? The task of doing this for each item in the spy report isn't too hard, when I've already coded the table with those variables and the input/output scripts too! How's $answerlength come into this, where is it assigned? When you use function, you use stuff like $needle, only in the funtion. In the code you just write $answer = function_name("gold mine", 5, $stringfromdatabase) and insted of "gold mine" you can use variable like $thisholdssomethingwearecurrentlylookingfor or just "Stone quarry" or "natmus pissed here" etc Same goes for the aswerlenght, but since you might be looking for different things, the lenght of the returned string must wary. For gold mine you just need to know 2 character, like 5 or 20, but if you want an answer for "natmus pissed here" you want to have longer reply, like"And because of that, it smells horrible"
|
|
|
Post by Old Shendemiar on Aug 15, 2005 14:18:16 GMT
Couple of other coding questions! Remind me how I call a function and pass the variables it wants, I've done this before but I've no example code I can get hold of right now. Can the function code be inside the main code or a separate php file? $ansver = funtion_name(paramter1, parameter2...) $ansver = function("dog, 2, "behind this tree dog lies low") $ansver= function($a,$b,"something" ************ <php echo "lsdhgsdlhfg"; function max($a, $b) { if $a>$b return $a else return $b } echo max(10, 20); echo "srkljhfsdkfjh"; ?> works, but its a generally good idea to colloect all functions to somewhere end of code, beginning of code, own file... just to make easier to find and maintain it.
|
|
SkulkrinBait
Morkin Admin
Haxx0rs == Suxx0rs! v4
Posts: 6,680
|
Post by SkulkrinBait on Aug 15, 2005 16:29:06 GMT
I got it working with Gold Mine so far, need to enter the other stuff for the other things we're interested in. Thanks again Robert.
One problem I have is dealing with things like Gold, which could be anywhere from 1 to 5 digits long, any advice how I might do that? I'm planning on assuming all variables are the max length they can be and them trimming them down, is there an easy way to trim spaces off the end or beginning of variables?
There are functions to determine is the given char is alphabetic or numeric... playing with these, locations, counts, lenghts etc, you can block out the unwanted parts.
|
|
SkulkrinBait
Morkin Admin
Haxx0rs == Suxx0rs! v4
Posts: 6,680
|
Post by SkulkrinBait on Aug 16, 2005 21:06:19 GMT
Bah, problems! Jst when I thought I had it sussed, thanks to Roberts help!
If you cut and paste direct from IK, it puts tabs in between Gold Mine and Level, for all the items I want to pick out! Is there a way of telling my code to either ignore tabs or put them into the string I am searching for? If I just put a tab into the code does that work? Heck, I'll try it and see!
Second problem is with amounts for Stonethrowers etc, if I say allow 4 or 5 chars for these, you might find the attacking force is included, can I tell the code to stop when it comes to a space in terms of length of $needle? In other words $needle should be trimmed of anything after the first space? Again I think this will be possible and in fact I might have some code from Pitstop which did that, amazing how things come back to you when you type, so ignore this, me thinking out loud! Pitstop was useful for something after all!
Finally island coordinates, you might get the wrong coordinates as it will read the spying persons coordinates first, I suppose I can loop thought the code twice to get the second coordinates which I need? Or maybe mask it, if the coordinate matches what you got first time ignore it or something.
Sorry to bug you with stupid questions!
|
|
Raven
Public Area Guest
Posts: 410
|
Post by Raven on Aug 16, 2005 21:17:38 GMT
Why not specify that the whole page needs to be copied
CTRL+A CTRL+C
and then
CTRL+V to your window.
That way you can expect the same values and verify etc
eg from attack mail
Mail
-------------------------------------------------------------------------------- 16.08.2005 22:15:56 | Settings | Invite a Friend | Logout | You SoulCatcher, are ruler of the isle Roses (31:19:9) 196 1657 152
Inbox | Outbox | Archive | Write a message
Attack report from 16.08.2005 22:05 Offence Units Roses (31:19:9) Total Losses Small Warship 3 0 Small Merchant Ship 3 0 Stone Thrower 3 0 Spearfighter 3 0 Defence Units unnamed (32:32:1) Total Losses Plundered Resources Gold 60 Stone 50 Lumber 45 Delete
-------------------------------------------------------------------------------- Overview | Alliance | Map | Isles | Market | Rank List | Calculator
0.008
|
|
SkulkrinBait
Morkin Admin
Haxx0rs == Suxx0rs! v4
Posts: 6,680
|
Post by SkulkrinBait on Aug 16, 2005 21:22:23 GMT
Great! That gets rid of the tabs! Thanks! A chocolate rat for you!
|
|