retoto Posted March 24, 2008 Share Posted March 24, 2008 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 and thanks Quote Link to comment https://forums.phpfreaks.com/topic/97634-2-questions/ Share on other sites More sharing options...
MadTechie Posted March 24, 2008 Share Posted March 24, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/97634-2-questions/#findComment-499558 Share on other sites More sharing options...
wildteen88 Posted March 24, 2008 Share Posted March 24, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/97634-2-questions/#findComment-499561 Share on other sites More sharing options...
retoto Posted March 24, 2008 Author Share Posted March 24, 2008 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 (?) Quote Link to comment https://forums.phpfreaks.com/topic/97634-2-questions/#findComment-499596 Share on other sites More sharing options...
wildteen88 Posted March 24, 2008 Share Posted March 24, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/97634-2-questions/#findComment-499608 Share on other sites More sharing options...
retoto Posted March 24, 2008 Author Share Posted March 24, 2008 i dont know any thing in js : so i cant make it without help ( lol ) and again jump to question 1 how i can do it with function echo and not in print_r Quote Link to comment https://forums.phpfreaks.com/topic/97634-2-questions/#findComment-499627 Share on other sites More sharing options...
papaface Posted March 24, 2008 Share Posted March 24, 2008 echo $array[1]; Quote Link to comment https://forums.phpfreaks.com/topic/97634-2-questions/#findComment-499631 Share on other sites More sharing options...
retoto Posted March 25, 2008 Author Share Posted March 25, 2008 Ok thanks all help alot but i serach for one function that spilt wirte like if i enter "84/21" so it well opent in array $array_1 = "84"; $array_2 = "21"; have for this function ? Quote Link to comment https://forums.phpfreaks.com/topic/97634-2-questions/#findComment-500206 Share on other sites More sharing options...
wildteen88 Posted March 25, 2008 Share Posted March 25, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/97634-2-questions/#findComment-500208 Share on other sites More sharing options...
ansarka Posted March 25, 2008 Share Posted March 25, 2008 function split_array($string,$splitter) { $textarea_text_array = explode($splitter, $string); return $textarea_text_array; } you can call this function like split_array('/', $string); split_array('/n', $string); Quote Link to comment https://forums.phpfreaks.com/topic/97634-2-questions/#findComment-500210 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.