Solved

Uploading and parsing formatted text via PHP, populating a MySQL database

Posted on 2007-03-30
4
621 Views
Last Modified: 2013-12-13
I'd like to create a field on a website that people could cut & paste information into. Then have a PHP script handle the upload and throw the information into a database. The data will ALWAYS be in this format:

_:. Government Information
Nation Name:      Tealopolis
Ruler:      Napolean
 Last Donation:      No donations on record.
Last Activity:      3/30/2007 9:41:31 AM
National Flag:       
 Alliance Affiliation:      none  
About Shaka Khan:      Ixnay Broheim Laborious  
 Government Type:      Anarchy (Next Available Change 4/2/2007)
Your people approve of this form of government but the majority of your people would prefer something else. They desire a government that is based on radical change.
 National Religion:            Mixed      (Next Available Change 3/25/2007)
Your people approve of this national religion but the majority of your people would prefer something else. They desire a modern middle eastern religion that focuses on monotheism.

 Nation Team:       - Black - Team Information Panel
Nation Created:      2/22/2007 4:43:25 PM (36 days old)
 Technology:       4.68
 Infrastructure:      68.11
 Tax Rate:      28%  (This high tax rate angers your citizens.)
Area of Influence:      32.533 mile diameter.
14.381 from purchases/sales/gains, 18.152 from natural growth.
 War/Peace Preference:       War is an option for Shaka Khan.
 My Resources:       
Connected Resources:       
 Bonus Resources:      None
 Improvements:      No improvements purchased.
 National Wonders:       No national wonders.
 Environment:       7.00
Senate Votes:      0 Votes
_:. Military Information
Nation Rank:      Ranked #30,157 of 37,981 total nations
 Nation Strength:      373.618
 Efficiency:      10.38
 DEFCON Level:       
 Number of Soldiers:      656
       Deployed Soldiers:
      0
       Defending Soldiers:
      656  
 Number of Tanks:      0
       Deployed Tanks:
      0
       Defending Tanks:
      0
 Aircraft:      0
 Number of Cruise Missiles:      0
 Number of Nuclear Weapons:      0
Number of Soldiers Lost in All Wars.      127 Attacking + 2,246 Defending = 2,373 Casualties
_:. Population Information
Total Population:      1,368 Supporters
Primary Ethnic Group:      Somali
 Population Happiness:       -10.30
Population Per Mile:      42.05 Population Per Mile.
       Military Personnel:
       Citizens:
      656 Soldiers
712 Working Citizens
Avg. Gross Income Per Individual Per Day:      $13.94  (A very weak economy)
Avg. Individual Income Taxes Paid Per Day      $3.90
Avg. Net Daily Population Income (After Taxes)      $10.04
_:. Government Financial
Current Dollars Available:      $2,731.23   (Surplus)

Yes, its for an online game :) I've played similiar games and some people have created websites where you paste the source from the page into an upload box, and then the website handles that information and makes it searchable (security?).  I'm creating an alliance CMS system for this particular game, and need to be able to use this information in a MySQL database. I'm relatively new to PHP & MySQL, but eager to learn.
0
Comment
Question by:bwsycom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 15

Accepted Solution

by:
JakobA earned 250 total points
ID: 18826358
If you trust people to adhere to the format you can use a LOAD DATA INFILE after storing the postdat from your textarea in a textfile.

It would be something like:

LOAD DATA INFILE fileNameofpostdata.txt
INTO TABLE tbl_name
FIELDS TERMINATED BY '\n'
LINES   TERMINATED BY '\n\n'

note that each field must be on a single line, so do not use the autowrap attribute in the textarea. and make sure that the data for each field, eg:

National Religion:            Mixed      (Next Available Change 3/25/2007)
Your people approve of this national religion but the majority of your people would prefer something else. They desire a modern middle eastern religion that focuses on monotheism.

is written without linefeeds

National Religion:            Mixed      (Next Available Change 3/25/2007) Your people approve of this national religion but the majority of your people would prefer something else. They desire a modern middle eastern religion that focuses on monotheism.

regards JakobA
0
 
LVL 3

Assisted Solution

by:yipeng
yipeng earned 250 total points
ID: 19127132
Use a TEXT data type.. that should maintain your formatting.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question