CSmith1128 Posted May 12, 2007 Share Posted May 12, 2007 Hello. I need some help filtering user input. I want to take text that a user inputs and store it into a variable. That's the easy part. I have and array of 30 elements that I want to store the inputted text into. So.. here's an example... - I want a user to enter text. - I'll store it into a variable like $inputText. - I want to split the text from $inputText into 30 equal sections and store each section into an element in the variable. - I don't care if the words get separated during the filter, as long as the whitespaces stay where they are. Could anyone give me some tips to help me get started or point me towards a tutorial or something? Thanks, Chris Quote Link to comment https://forums.phpfreaks.com/topic/51035-solved-need-some-help-filtering-user-input/ Share on other sites More sharing options...
Barand Posted May 12, 2007 Share Posted May 12, 2007 <?php $userText = "Lorem ipsum dolor sito amet, atoi consectetuer adipiscing elit, sed diam nonummy nibal as eui mode. Visit autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi."; /** * get the length and find length of the 30 portions */ $len = strlen($userText); $plen = ceil($len/30); /** * now go through text, plen chars at a time, and put them in the array */ $textArray = array(); for ($i=0; $i < $len; $i+=$plen) { $textArray[] = substr($userText, $i, $plen); } /** * view results */ echo '<pre>', print_r($textArray, true), '</pre>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/51035-solved-need-some-help-filtering-user-input/#findComment-251253 Share on other sites More sharing options...
otuatail Posted May 12, 2007 Share Posted May 12, 2007 Would this not be easy $userText = "Lorem ipsum dolor sito amet, atoi consectetuer adipiscing elit, sed diam nonummy nibal as eui mode. Visit autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi."; $textArray = split(' ', $userTex); Quote Link to comment https://forums.phpfreaks.com/topic/51035-solved-need-some-help-filtering-user-input/#findComment-251295 Share on other sites More sharing options...
Barand Posted May 12, 2007 Share Posted May 12, 2007 Yes, if the problem was to split it into array of 59 words Quote Link to comment https://forums.phpfreaks.com/topic/51035-solved-need-some-help-filtering-user-input/#findComment-251303 Share on other sites More sharing options...
CSmith1128 Posted May 13, 2007 Author Share Posted May 13, 2007 thanks! Quote Link to comment https://forums.phpfreaks.com/topic/51035-solved-need-some-help-filtering-user-input/#findComment-251750 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.