Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    34
    Thanks
    2
    Thanked 1 Time in 1 Post

    Not Exploding Correctly?

    It isn't exploding correctly, I think it is the first one:
    $spell = explode("\n"."\n", $text);

    link
    Complete(but not finished)
    PHP Code:
    <?php
      
      $text 
    $_POST['text'];
      
      
    $spell explode("\n"."\n"$text);
      
      for(
    $i=0$spell[$i]; $i++)
      {
        
    $line[$i] = explode("\n"$spell[$i]);
      }
      
      for(
    $i=0$line[$i]; $i++)
      {
        for(
    $j=0$line[$i][$j]; $j++)
        {
          
    $atributes[$i][$j] = explode(":"$line[$i][$j]);
        }
      }

      for(
    $i=0$atributes[$i]; $i++)
      {
        echo 
    "Spell: ".$atributes[$i][0][0]."<br>";
        echo 
    "School: ".$atributes[$i][1][0]."<br>";
        echo 
    "<br>";
      }
    ?>
    A piece of the submitted text:
    Code:
    Acid Arrow
    Conjuration (Creation) [Acid]
    Level: Sor/Wiz 2
    Components: V, S, M, F
    Casting Time: 1 standard action
    Range: Long (400 ft. + 40 ft./level)
    Effect: One arrow of acid
    Duration: 1 round + 1 round per three levels
    Saving Throw: None
    Spell Resistance: No
    A magical arrow of acid springs from your hand and speeds to its target. You must succeed on a ranged touch attack to hit your target. The arrow deals 2d4 points of acid damage with no splash damage. For every three caster levels (to a maximum of 18th), the acid, unless somehow neutralized, lasts for another round, dealing another 2d4 points of damage in that round.
    Material Component: Powdered rhubarb leaf and an adder’s stomach.
    Focus: A dart.
    
    Acid Fog
    Conjuration (Creation) [Acid]
    Level: Sor/Wiz 6, Water 7
    Components: V, S, M/DF
    Casting Time: 1 standard action
    Range: Medium (100 ft. + 10 ft./level)
    Effect: Fog spreads in 20-ft. radius, 20 ft. high
    Duration: 1 round/level
    Saving Throw: None
    Spell Resistance: No
    Acid fog creates a billowing mass of misty vapors similar to that produced by a solid fog spell. In addition to slowing creatures down and obscuring sight, this spell’s vapors are highly acidic. Each round on your turn, starting when you cast the spell, the fog deals 2d6 points of acid damage to each creature and object within it.
    Arcane Material Component: A pinch of dried, powdered peas combined with powdered animal hoof.
    
    Acid Splash
    Conjuration (Creation) [Acid]
    Level: Sor/Wiz 0
    Components: V, S
    Casting Time: 1 standard action
    Range: Close (25 ft. + 5 ft./2 levels)
    Effect: One missile of acid
    Duration: Instantaneous
    Saving Throw: None
    Spell Resistance: No
    You fire a small orb of acid at the target. You must succeed on a ranged touch attack to hit your target. The orb deals 1d3 points of acid damage.
    var_dump() of $atributes
    Code:
    array(1) {
      [0]=>
      array(65) {
        [0]=>
        array(1) {
          [0]=>
          string(11) "Acid Arrow
    "
        }
        [1]=>
        array(1) {
          [0]=>
          string(30) "Conjuration (Creation) [Acid]
    "
        }
        [2]=>
        array(2) {
          [0]=>
          string(5) "Level"
          [1]=>
          string(11) " Sor/Wiz 2
    "
        }
        [3]=>
        array(2) {
          [0]=>
          string(10) "Components"
          [1]=>
          string(12) " V, S, M, F
    "
        }
        [4]=>
        array(2) {
          [0]=>
          string(12) "Casting Time"
          [1]=>
          string(19) " 1 standard action
    "
        }
        [5]=>
        array(2) {
          [0]=>
          string(5) "Range"
          [1]=>
          string(31) " Long (400 ft. + 40 ft./level)
    "
        }
        [6]=>
        array(2) {
          [0]=>
          string(6) "Effect"
          [1]=>
          string(19) " One arrow of acid
    "
        }
        [7]=>
        array(2) {
          [0]=>
          string(8) "Duration"
          [1]=>
          string(36) " 1 round + 1 round per three levels
    "
        }
        [8]=>
        array(2) {
          [0]=>
          string(12) "Saving Throw"
          [1]=>
          string(6) " None
    "
        }
        [9]=>
        array(2) {
          [0]=>
          string(16) "Spell Resistance"
          [1]=>
          string(4) " No
    "
        }
        [10]=>
        array(1) {
          [0]=>
          string(369) "A magical arrow of acid springs from your hand and speeds to its target. You must succeed on a ranged touch attack to hit your target. The arrow deals 2d4 points of acid damage with no splash damage. For every three caster levels (to a maximum of 18th), the acid, unless somehow neutralized, lasts for another round, dealing another 2d4 points of damage in that round.
    "
        }
        [11]=>
        array(2) {
          [0]=>
          string(18) "Material Component"
          [1]=>
          string(47) " Powdered rhubarb leaf and an adder’s stomach.
    "
        }
        [12]=>
        array(2) {
          [0]=>
          string(5) "Focus"
          [1]=>
          string(9) " A dart.
    "
        }
        [13]=>
        array(1) {
          [0]=>
          string(1) "
    "
        }
        [14]=>
        array(1) {
          [0]=>
          string(9) "Acid Fog
    "
        }
        [15]=>
        array(1) {
          [0]=>
          string(30) "Conjuration (Creation) [Acid]
    "
        }
        [16]=>
        array(2) {
          [0]=>
          string(5) "Level"
          [1]=>
          string(20) " Sor/Wiz 6, Water 7
    "
        }
        [17]=>
        array(2) {
          [0]=>
          string(10) "Components"
          [1]=>
          string(12) " V, S, M/DF
    "
        }
        [18]=>
        array(2) {
          [0]=>
          string(12) "Casting Time"
          [1]=>
          string(19) " 1 standard action
    "
        }
        [19]=>
        array(2) {
          [0]=>
          string(5) "Range"
          [1]=>
          string(33) " Medium (100 ft. + 10 ft./level)
    "
        }
        [20]=>
        array(2) {
          [0]=>
          string(6) "Effect"
          [1]=>
          string(43) " Fog spreads in 20-ft. radius, 20 ft. high
    "
        }
        [21]=>
        array(2) {
          [0]=>
          string(8) "Duration"
          [1]=>
          string(15) " 1 round/level
    "
        }
        [22]=>
        array(2) {
          [0]=>
          string(12) "Saving Throw"
          [1]=>
          string(6) " None
    "
        }
        [23]=>
        array(2) {
          [0]=>
          string(16) "Spell Resistance"
          [1]=>
          string(4) " No
    "
        }
        [24]=>
        array(1) {
          [0]=>
          string(333) "Acid fog creates a billowing mass of misty vapors similar to that produced by a solid fog spell. In addition to slowing creatures down and obscuring sight, this spell’s vapors are highly acidic. Each round on your turn, starting when you cast the spell, the fog deals 2d6 points of acid damage to each creature and object within it.
    "
        }
        [25]=>
        array(2) {
          [0]=>
          string(25) "Arcane Material Component"
          [1]=>
          string(69) " A pinch of dried, powdered peas combined with powdered animal hoof.
    "
        }
        [26]=>
        array(1) {
          [0]=>
          string(1) "
    "
        }
        [27]=>
        array(1) {
          [0]=>
          string(12) "Acid Splash
    "
        }
        [28]=>
        array(1) {
          [0]=>
          string(30) "Conjuration (Creation) [Acid]
    "
        }
        [29]=>
        array(2) {
          [0]=>
          string(5) "Level"
          [1]=>
          string(11) " Sor/Wiz 0
    "
        }
        [30]=>
        array(2) {
          [0]=>
          string(10) "Components"
          [1]=>
          string(6) " V, S
    "
        }
        [31]=>
        array(2) {
          [0]=>
          string(12) "Casting Time"
          [1]=>
          string(19) " 1 standard action
    "
        }
        [32]=>
        array(2) {
          [0]=>
          string(5) "Range"
          [1]=>
          string(33) " Close (25 ft. + 5 ft./2 levels)
    "
        }
        [33]=>
        array(2) {
          [0]=>
          string(6) "Effect"
          [1]=>
          string(21) " One missile of acid
    "
        }
        [34]=>
        array(2) {
          [0]=>
          string(8) "Duration"
          [1]=>
          string(15) " Instantaneous
    "
        }
        [35]=>
        array(2) {
          [0]=>
          string(12) "Saving Throw"
          [1]=>
          string(6) " None
    "
        }
        [36]=>
        array(2) {
          [0]=>
          string(16) "Spell Resistance"
          [1]=>
          string(4) " No
    "
        }
        [37]=>
        array(1) {
          [0]=>
          string(147) "You fire a small orb of acid at the target. You must succeed on a ranged touch attack to hit your target. The orb deals 1d3 points of acid damage.
    "
        }
        [38]=>
        array(1) {
          [0]=>
          string(1) "
    "
        }
        [39]=>
        array(1) {
          [0]=>
          string(4) "Aid
    "
        }
        [40]=>
        array(1) {
          [0]=>
          string(42) "Enchantment (Compulsion) [Mind-Affecting]
    "
        }
        [41]=>
        array(2) {
          [0]=>
          string(5) "Level"
          [1]=>
          string(23) " Clr 2, Good 2, Luck 2
    "
        }
        [42]=>
        array(2) {
          [0]=>
          string(10) "Components"
          [1]=>
          string(10) " V, S, DF
    "
        }
        [43]=>
        array(2) {
          [0]=>
          string(12) "Casting Time"
          [1]=>
          string(19) " 1 standard action
    "
        }
        [44]=>
        array(2) {
          [0]=>
          string(5) "Range"
          [1]=>
          string(7) " Touch
    "
        }
        [45]=>
        array(2) {
          [0]=>
          string(6) "Target"
          [1]=>
          string(25) " Living creature touched
    "
        }
        [46]=>
        array(2) {
          [0]=>
          string(8) "Duration"
          [1]=>
          string(14) " 1 min./level
    "
        }
        [47]=>
        array(2) {
          [0]=>
          string(12) "Saving Throw"
          [1]=>
          string(6) " None
    "
        }
        [48]=>
        array(2) {
          [0]=>
          string(16) "Spell Resistance"
          [1]=>
          string(16) " Yes (harmless)
    "
        }
        [49]=>
        array(1) {
          [0]=>
          string(210) "Aid grants the target a +1 morale bonus on attack rolls and saves against fear effects, plus temporary hit points equal to 1d8 + caster level (to a maximum of 1d8+10 temporary hit points at caster level 10th).
    "
        }
        [50]=>
        array(1) {
          [0]=>
          string(1) "
    "
        }
        [51]=>
        array(1) {
          [0]=>
          string(9) "Air Walk
    "
        }
        [52]=>
        array(1) {
          [0]=>
          string(20) "Transmutation [Air]
    "
        }
        [53]=>
        array(2) {
          [0]=>
          string(5) "Level"
          [1]=>
          string(21) " Air 4, Clr 4, Drd 4
    "
        }
        [54]=>
        array(2) {
          [0]=>
          string(10) "Components"
          [1]=>
          string(10) " V, S, DF
    "
        }
        [55]=>
        array(2) {
          [0]=>
          string(12) "Casting Time"
          [1]=>
          string(19) " 1 standard action
    "
        }
        [56]=>
        array(2) {
          [0]=>
          string(5) "Range"
          [1]=>
          string(7) " Touch
    "
        }
        [57]=>
        array(2) {
          [0]=>
          string(6) "Target"
          [1]=>
          string(42) " Creature (Gargantuan or smaller) touched
    "
        }
        [58]=>
        array(2) {
          [0]=>
          string(8) "Duration"
          [1]=>
          string(15) " 10 min./level
    "
        }
        [59]=>
        array(2) {
          [0]=>
          string(12) "Saving Throw"
          [1]=>
          string(6) " None
    "
        }
        [60]=>
        array(2) {
          [0]=>
          string(16) "Spell Resistance"
          [1]=>
          string(16) " Yes (harmless)
    "
        }
        [61]=>
        array(1) {
          [0]=>
          string(227) "The subject can tread on air as if walking on solid ground. Moving upward is similar to walking up a hill. The maximum upward or downward angle possible is 45 degrees, at a rate equal to one-half the air walker’s normal speed.
    "
        }
        [62]=>
        array(1) {
          [0]=>
          string(361) "A strong wind (21+ mph) can push the subject along or hold it back. At the end of its turn each round, the wind blows the air walker 5 feet for each 5 miles per hour of wind speed. The creature may be subject to additional penalties in exceptionally strong or turbulent winds, such as loss of control over movement or physical damage from being buffeted about.
    "
        }
        [63]=>
        array(1) {
          [0]=>
          string(479) "Should the spell duration expire while the subject is still aloft, the magic fails slowly. The subject floats downward 60 feet per round for 1d6 rounds. If it reaches the ground in that amount of time, it lands safely. If not, it falls the rest of the distance, taking 1d6 points of damage per 10 feet of fall. Since dispelling a spell effectively ends it, the subject also descends in this way if the air walk spell is dispelled, but not if it is negated by an antimagic field.
    "
        }
        [64]=>
        array(1) {
          [0]=>
          string(243) "You can cast air walk on a specially trained mount so it can be ridden through the air. You can train a mount to move with the aid of air walk (counts as a trick; see Handle Animal skill) with one week of work and a DC 25 Handle Animal check.
    "
    Last edited by Big-Pat; 01-11-2008 at 05:58 AM.

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    I don't see any issue with the explode call. If you call print_r($spells) right after that, it will print out the array that was created.

    I think you need to re-work some of the for loops at the bottom. Particularly, I am not familiar with this syntax: for($i=0; $line[$i]; $i++). I'm not sure what the $line[$i] condition is supposed to be doing. Typically you would compare $i to the size of the array: for($i=0; $i<=count($line); $i++).

    Here is some code I wrote up real quick. I changed the data by adding a "spell:" and "school:" identifier but this gives you a nice associative indexed array separated by each spell:

    PHP Code:
    <?php
    $text
    ='
    Spell: Acid Arrow
    School: Conjuration (Creation) [Acid]
    Level: Sor/Wiz 2
    Components: V, S, M, F
    Casting Time: 1 standard action
    Range: Long (400 ft. + 40 ft./level)
    Effect: One arrow of acid
    Duration: 1 round + 1 round per three levels
    Saving Throw: None
    Spell Resistance: No
    A magical arrow of acid springs from your hand and speeds to its target. You must succeed on a ranged touch attack to hit your target. The arrow deals 2d4 points of acid damage with no splash damage. For every three caster levels (to a maximum of 18th), the acid, unless somehow neutralized, lasts for another round, dealing another 2d4 points of damage in that round.
    Material Component: Powdered rhubarb leaf and an adderís stomach.
    Focus: A dart.

    Spell: Acid Fog
    School: Conjuration (Creation) [Acid]
    Level: Sor/Wiz 6, Water 7
    Components: V, S, M/DF
    Casting Time: 1 standard action
    Range: Medium (100 ft. + 10 ft./level)
    Effect: Fog spreads in 20-ft. radius, 20 ft. high
    Duration: 1 round/level
    Saving Throw: None
    Spell Resistance: No
    Acid fog creates a billowing mass of misty vapors similar to that produced by a solid fog spell. In addition to slowing creatures down and obscuring sight, this spellís vapors are highly acidic. Each round on your turn, starting when you cast the spell, the fog deals 2d6 points of acid damage to each creature and object within it.
    Arcane Material Component: A pinch of dried, powdered peas combined with powdered animal hoof.

    Spell: Acid Splash
    School: Conjuration (Creation) [Acid]
    Level: Sor/Wiz 0
    Components: V, S
    Casting Time: 1 standard action
    Range: Close (25 ft. + 5 ft./2 levels)
    Effect: One missile of acid
    Duration: Instantaneous
    Saving Throw: None
    Spell Resistance: No
    You fire a small orb of acid at the target. You must succeed on a ranged touch attack to hit your target. The orb deals 1d3 points of acid damage.
    '
    ;

    $spells explode("\n"."\n"$text);
    $i=0;

    foreach(
    $spells as $spell)
    {
        
    $spellRows explode("\n"$spell);
        foreach(
    $spellRows as $spellRow)
        {
            list(
    $attributeName$attributeValue)=explode(":"$spellRow);
            
    $attributes[$i][$attributeName]=$attributeValue;
        }
        
    $i++;
    }


    print 
    "<pre>";
    print_r($attributes);
    print 
    "</pre>";
    ?>

  • #3
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    You just said it isn't "exploding correctly". What is your expected outcome? And what is the actual outcome? And why do you concatenate "\n" within the first parameter instead of just having them in one string?

    Did you mean to explode on \r\n instead of \n\n?
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • Users who have thanked StupidRalph for this post:

    Big-Pat (01-11-2008)

  • #4
    New Coder
    Join Date
    May 2006
    Posts
    34
    Thanks
    2
    Thanked 1 Time in 1 Post
    Quote Originally Posted by arnyinc View Post
    I don't see any issue with the explode call. If you call print_r($spells) right after that, it will print out the array that was created.

    I think you need to re-work some of the for loops at the bottom. Particularly, I am not familiar with this syntax: for($i=0; $line[$i]; $i++). I'm not sure what the $line[$i] condition is supposed to be doing. Typically you would compare $i to the size of the array: for($i=0; $i<=count($line); $i++).

    Here is some code I wrote up real quick. I changed the data by adding a "spell:" and "school:" identifier but this gives you a nice associative indexed array separated by each spell:
    "for($i=0; $line[$i]; $i++)" basically is a while loop (while something is in $line[$i]), but I put it in a for just to make it a little cleaner.
    I can't change the text being inputted, there are way to many to change. The point is to eventually put them into a database.

    Quote Originally Posted by StupidRalph View Post
    You just said it isn't "exploding correctly". What is your expected outcome? And what is the actual outcome? And why do you concatenate "\n" within the first parameter instead of just having them in one string?

    Did you mean to explode on \r\n instead of \n\n?
    Actually it looks like \n\r works how I need it to. Thanks, I didn't know there was a difference between \n and \r.
    Last edited by Big-Pat; 01-11-2008 at 04:45 PM. Reason: spelling

  • #5
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    \r is a carriage return
    \n is a new line

    Windows uses a combination of a carriage return and new line when you press the Enter key. The carriage return (\r) moves the cursor back to the left side of the window. The new line (\n) starts a new line beneath.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •