TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-15-2008, 04:16 PM   #1 (permalink)
The Contributor
 
Evulness's Avatar
 
Join Date: Apr 2008
Location: Tampa, FL
Posts: 65
Thanks: 6
Evulness is on a distinguished road
Default arrays

i've been having an issue lately, on breaking textarea input from a form, and breaking it down to an array
im writing a script to calculate how much more skill a character needs before they hit their next level. For a MUD i've been playing for 10 years...

so far i have
Code:
<form name="reqs" action="<?php $_SERVER[PHP_SELF]; ?>" method="POST">
<textarea name="text" rows="30" cols="10"></textarea>
<input type="submit" name="submit" value="submit" />
</form>
<?php
$text=$_POST['text'];
preg_match_all('/(([a-z]+ )*[a-z]+): +(\d+)/i', $text, $matches, PREG_SET_ORDER);
foreach($matches as $key=>$value)
    {
        echo $key.': '.$value.'<br />';
    }
    ?>
here is a small clip of the text that will be paste into my textarea box.

Quote:
Primary Magic: 43 80% clear Harness Ability: 46 33% clear
Power Perceive: 43 92% clear Magical Devices: 46 16% clear
Targeted Magic: 33 85% clear Evasion: 43 01% clear
Climbing: 36 52% clear Perception: 30 16% clear
Hiding: 34 37% clear Lockpicking: 4 37% clear
Disarm Traps: 2 05% clear Stalking: 30 93% clear
this is only part of the text... theres probably 40 lines like that...
i'm trying to break each skill down like this

<skill>: <#>
i only need the word(or words) before, and the first non-% number from each "set"

right now... all my script outputs is...
0: Array
1: Array
2: Array
3: Array
4: Array
5: Array
6: Array
7: Array
8: Array
9: Array
10: Array
11: Array

....
any ideas?
Send a message via AIM to Evulness
Evulness is offline  
Reply With Quote
Old 04-15-2008, 04:26 PM   #2 (permalink)
The Contributor
 
Evulness's Avatar
 
Join Date: Apr 2008
Location: Tampa, FL
Posts: 65
Thanks: 6
Evulness is on a distinguished road
Default

Der
never mind i figured it out :)

Code:
foreach($matches as $match)
    {
        echo $match['1'].': '.$match['3'].'<br />';
    }
outputs
Primary Magic: 43
Harness Ability: 46
Power Perceive: 43
Magical Devices: 46
Targeted Magic: 33
Evasion: 43
Climbing: 36
Perception: 30
Hiding: 34
Lockpicking: 4
Disarm Traps: 2
Stalking: 30
Send a message via AIM to Evulness
Evulness is offline  
Reply With Quote
Old 04-15-2008, 06:12 PM   #3 (permalink)
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 166
Thanks: 0
wGEric is on a distinguished road
Default

Technically it should be $match[1] and $match[3]. Those aren't strings but integers when they are put into the $matches array.
__________________
Eric
wGEric is offline  
Reply With Quote
Old 04-15-2008, 06:21 PM   #4 (permalink)
The Contributor
 
Evulness's Avatar
 
Join Date: Apr 2008
Location: Tampa, FL
Posts: 65
Thanks: 6
Evulness is on a distinguished road
Default

wops, thnx for catching that... i thought it would set the skillnames as the key, not as a value...
i'm not sure why, but i was trying to echo $match['$key'].':'.$match['$value'].'<br />'; at first...
i think i set them like that for place holders at first....then changed them to the place int for the array, when i got an error...
idk oh well.... it works now...

now i just have to figure out how to turn a... 150 row, 16+ column html table into an array, then i'm golden on this script
Send a message via AIM to Evulness
Evulness is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:03 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design