SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    south jersey
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Grabbing ASCII Text & Assiging to Variables

    Hiyas, I recently finished a simple database to store item information for a game I play, and am trying to make it easier for users to submit new items. I've been looking around but can't find anything on this topic. Is it possible to have a text field on a form, so a user can just copy and paste a snippet of something, and take parts of the text and assign them to variables?

    For more clarification, I just want to be able to copy and paste this into a text field:


    Glass Bracers
    -=-=-=- Worn Armour Evaluation -=-=-=-

    Edged: Ineffective Electric: Pathetic
    Blunt: Ineffective Mind: Pathetic
    Fire: Flimsy Energy: Pathetic
    Ice: Flimsy Poison: Pathetic
    Acid: Pathetic Radiation: Pathetic
    ============================================

    (The items in bold will be assigned to variables upon form submit)


    Could anyone point me to a direction where I could quickly accomplish this?
    (website: www.3karmour.ssxh.net)

    Thanks.

  2. #2
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have a look a regular expression matching (preg_match), this should help you out.

    -Peter

  3. #3
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Gainesville, Fl
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks petesmc!

  4. #4
    SitePoint Member
    Join Date
    Jan 2005
    Location
    south jersey
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot for the info, I've been delving into it and it's exactly what I need, but I'm having a real hard time matching the patterns. I've been doing some reading on pattern modifiers but am really confused. How would I grab the item name and Edged rating if the output were like this:

    Item Name
    -=-=-=- Worn Armour Evaluation -=-=-=-

    Edged: Rating

    I need to assign 'Item name' to the $name variable, and 'Rating' to the variable $edged. So far I've got:

    PHP Code:
    preg_match("/^(?)Edged:(?)^/"$description$matches);
    $name $matches[1];
    $edged $matches[2]; 
    As you can see I am completely stumped on the syntax of pattern modifiers. Could anyone please help?


Bookmarks

Posting Permissions

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