Jump to content

Recommended Posts

Hi all,

i have 2  lil questions for you

 

1 how can i make array in textarea

like some one wirte in textarea txt so it is get in to array

like some one enter

"the

man

well"

so the array well be $array = array('the', 'man', 'well');

 

2

i dont know exactly if its js or php

but anyaway i need script that show the txt i well enter in textarea on live

like if i enter txt "Hi all " so i well see it on another textarea onlive

 

sorry abut my sucks english  ;D

and thanks

Link to comment
https://forums.phpfreaks.com/topic/97634-2-questions/
Share on other sites

your recieve the string ie

the man well

 

so

$theSring = "the man well"

then your break it up into an array ie

$theArray = explode(" ",$theString); // the " " means space delimitor

 

so

<?php
$theArray = explode(" ",$_POST['theText']);
print_r($theArray);

?>

 

for the 2nd one, well you probably best storing the posted data, in a file or Database, then when the other client machines refesh it displays that data stored!

Link to comment
https://forums.phpfreaks.com/topic/97634-2-questions/#findComment-499558
Share on other sites

1. Simply do:

$textarea_text = $_POST['textarea_name'];
$textarea_text_array = explode("\n", $textarea_txt);

echo '<pre>' . print_r($textare_text_array, true) . '</pre>';

 

Edit: beaten by MadTechie

 

2. That will be done in javascript.

 

 

 

 

Ok thank you all ppl

and what the name of his script? or you can give me that script i well be grateful to you

(?)

Link to comment
https://forums.phpfreaks.com/topic/97634-2-questions/#findComment-499596
Share on other sites

All it'll take is one line of javascript, something like:

<textarea onkeyup="document.textarea2.value=this.value"></textarea>

Create another textarea and give it an id of textarea2, eg:

<textarea id="textarea2"></textarea>

 

It may not work, it is only for an example code. However do test it.

Link to comment
https://forums.phpfreaks.com/topic/97634-2-questions/#findComment-499608
Share on other sites

It is better to use an array then separate variables. I'm asumming you're using my code

 

So if someone entered

"one

two

three"

 

into the text box (Minus the quotes). Then to get the first word you'd use $textarea_text_array[0], to get the second you'd use $textarea_text_array[1] and finally $textarea_text_array[2] to get the last. Arrays start at zeros. I know when using arrays for the first time it seems confusing however arrays can very helpful when used in the correct way.

 

My code is just an example, you can change the variable $textarea_text_array to shorter one instead, by simple changing, this line:

$textarea_text_array = explode("\n", $textarea_txt);

 

to:

$words = explode("\n", $textarea_txt);

Then use $words[0],  $words[1], $words[2] to retrieve the words.

 

To understand arrays further I encourage you to have a read of the manual on arrays.

Link to comment
https://forums.phpfreaks.com/topic/97634-2-questions/#findComment-500208
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.