LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-17-2011, 02:19 PM   #1
rakshita09
LQ Newbie
 
Registered: Apr 2011
Posts: 11

Rep: Reputation: 0
php


OS:ubuntu


$text = My text1
My text2
My text3;

i want to know how to split the above sting which are present in the new line and this should be stored in an array using php.

output should be like this
arr[0]:My text1
arr[1]:My text2
arr[2]:My text3


i tried with explode("\n", $text);but its not working


thnks fo help in advance
 
Old 04-17-2011, 03:02 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Gee -

Too bad you didn't cut/paste your code for "explode()", or explain exactly *how* it "didn't work"...
... but you should find the answer to your question on this page:

http://php.net/manual/en/language.types.array.php
<= Gives much useful info; many good alternatives
 
Old 04-18-2011, 04:50 AM   #3
rakshita09
LQ Newbie
 
Registered: Apr 2011
Posts: 11

Original Poster
Rep: Reputation: 0
its displaying the output like this for explode() function
string[0]=My text1
My text2
My text2
like everything is getting stored in array[0] only
 
Old 04-18-2011, 09:35 AM   #4
Asido
Member
 
Registered: Jan 2010
Location: Denmark
Distribution: Gentoo, Archlinux, FreeBSD, Slackware
Posts: 84

Rep: Reputation: 24
Try explode with '\r'
 
Old 04-18-2011, 10:00 AM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Try explode with '\r'
<= This might be necessarily if you were typing your text file in DOS/Windows (instead of Linux).

Q: Are you creating your text in Windows?
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Installing Nginx With PHP 5.3 And PHP-FPM On Ubuntu Lucid Lynx (10.04) LXer Syndicated Linux News 0 06-14-2010 11:42 PM
LXer: Installing PHP 5.3, Nginx And PHP-fpm On Ubuntu/Debian LXer Syndicated Linux News 0 02-10-2010 05:40 PM
You have chosen to open index.php which is a : PHP Script from: http://localhost cucolin@ Linux - Software 3 01-30-2007 03:58 PM
Adding users with PHP (pass php variables to Expect script) Jayla Programming 1 10-20-2006 10:44 AM
php apache or php cgi - php learner rblampain Linux - Security 3 12-17-2004 11:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration