/    Sign up×
Community /Pin to ProfileBookmark

textbox to array

I’d like to load textbox content to array line by line, like this:

textbox

[QUOTE]

name
surname
phone
email

[/QUOTE]

array

[QUOTE]

Array[0] = “name”
Array[1] = “surname”
Array[2] = “phone”
Array[3] = “email”

[/QUOTE]

I tried this way but it doesn’t work:

[QUOTE]

$person = $rows[‘textbox’];
$Array = explode(‘n’, $person);

[/QUOTE]

to post a comment
PHP

17 Comments(s)

Copy linkTweet thisAlerts:
@PprakashApr 28.2010 — where was you put textarea, i mean in the form or in the directly php script. when you convert data in textarea into array. please learly explined.

but i give one sugesion,

tried r insted of n , and also tried split insted of explode function
Copy linkTweet thisAlerts:
@HelleshternauthorApr 28.2010 — I have it into a form.
Copy linkTweet thisAlerts:
@PprakashApr 28.2010 — when was you want to data into array, after submission or before submission.
Copy linkTweet thisAlerts:
@HelleshternauthorApr 28.2010 — After submit. I want read textbox line by line to later post specific array lines to database.
Copy linkTweet thisAlerts:
@JonaApr 28.2010 — [font=arial]Hi,

Try using double-quotes instead of a string literal. The single-quotes will search for n, but the double-quotes will search for a linefeed.[/font]
Copy linkTweet thisAlerts:
@HelleshternauthorApr 28.2010 — I did but it doesn't help. I tried "n", "r" and "rn" with explode and split but no result.
Copy linkTweet thisAlerts:
@JonaApr 28.2010 — [font=arial]Are you getting the full string? If you echo out $rows['textarea'], do you get the full result?[/font]
Copy linkTweet thisAlerts:
@HelleshternauthorApr 28.2010 — Yes I do. After trying to split or explode I'm getting full string as Array[0] and it looks like "name surname phone email".
Copy linkTweet thisAlerts:
@JonaApr 28.2010 — [font=arial]The code you have should work. You could be extra careful and split via regexps, but that seems like overkill.

If you view the source of that output, are they new lines or spaces in the resulting HTML?[/font]
Copy linkTweet thisAlerts:
@HelleshternauthorApr 28.2010 — New lines as:

name

surname

phone

email [/QUOTE]
Copy linkTweet thisAlerts:
@JonaApr 28.2010 — [font=arial]Strange... This doesn't work?[/font]

[code=php]
$person = $rows['textbox'];
$Array = explode("n", $person);

print_r ($Array);
[/code]
Copy linkTweet thisAlerts:
@HelleshternauthorApr 28.2010 — It's giving empty result:


Array

(

[0] =>

)
[/QUOTE]
Copy linkTweet thisAlerts:
@ChipzzzApr 28.2010 — It looked right to me, too, so I tried this:
<i>
</i>$person = "NamenSurnamenSomethingnSomething else";
$Array = explode("n", $person);

print_r ($Array);


and it worked as expected:
<i>
</i>Array
(
[0] =&gt; Name
[1] =&gt; Surname
[2] =&gt; Something
[3] =&gt; Something else
)


It would seem likely that there must be something wrong with the line:
<i>
</i>$person = $rows['textbox'];


but without seeing the rest of the code there is no way to know what.

I hope this helps.
Copy linkTweet thisAlerts:
@HelleshternauthorApr 28.2010 — Oh my god you're right!

Instead:
$person = $rows['textbox'];[/QUOTE]

Should be:
$person = $_POST['textbox'];[/QUOTE]

That was the problem and I didn't noticed it before. Now it works.

[B]Thank you all for your time.[/B]
Copy linkTweet thisAlerts:
@JonaApr 28.2010 — Oh my god you're right!

That was the problem and I didn't noticed it before. Now it works.

[B]Thank you all for your time.[/B][/QUOTE]


[font=arial]This is why I asked if the output was what you expected. I'm curious how you managed to get output as you described if you weren't using that variable. ;-)

I would recommend turning on strict error reporting so that PHP will produce notifications when you attempt to reference the value of an unset variable. It should help with your debugging process.[/font]
Copy linkTweet thisAlerts:
@ChipzzzApr 29.2010 — Happy to be of service ?
Copy linkTweet thisAlerts:
@PprakashApr 29.2010 — finally you got result, after submit data via post method the data at server stored in $_POST array
×

Success!

Help @Helleshtern spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...