We help IT Professionals succeed at work.

entering text into db and spliting it up

runnerjp
runnerjp asked
on
Medium Priority
188 Views
Last Modified: 2013-12-12
if i have a textbox and in it i have

data1
data2

so each text on a different line..


could i insert that into my db and then pull it out and explode it so i can echo "data1";  and echo "data2"  if that makes sence?
Comment
Watch Question

Web Developer, specialising in WordPress
CERTIFIED EXPERT
Most Valuable Expert 2011
Commented:
Yes, something like this should work once you've got the data out of the db:

foreach(explode("\n",$textbox_contents) as $line) {
  print "$line<br \>\n";
}

If you ever want to look at a subset of the lines though, you would be best to separate them before putting them in the db.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
how would i seperate them before into the db?
Most Valuable Expert 2011
Author of the Year 2014
Commented:
To break the lines up correctly before putting the information into the data base, look at nl2br() and see especially this note:
http://us3.php.net/manual/en/function.nl2br.php#78883

Then you could do something like explode('</p>,p>', $data);

HTH, ~Ray
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.