doa24uk Posted March 19, 2010 Share Posted March 19, 2010 Hi guys, I've got a textarea input .... I'm aware that I can't count / restrict the lines only the characters ... plus I don't want to use JS (needs to be foolproof / JS un-enabled proof). The problem is that someone can submit as many lines as they wish. I want to set the max array size (array values) to say 50... I presume I'll have to count() the array and then somehow dump the 51st, 52nd, n... values in the array? Quote Link to comment https://forums.phpfreaks.com/topic/195841-restrict-array-size-length/ Share on other sites More sharing options...
doa24uk Posted March 19, 2010 Author Share Posted March 19, 2010 Solved .... For those looking for the same thing.... array_slice // Get Textarea string $textarea = $_POST['phrase']; // Explode textarea on newlines to get individual search phrases $textarea_array = explode("\n", $textarea); // Slice off the unwanted items // First value should be 0 (start of array) // Second value should be your upper limit (10 in my case) // Anything about the upper limit will be removed $ResultArray = array_slice($textarea_array, 0, 10); Quote Link to comment https://forums.phpfreaks.com/topic/195841-restrict-array-size-length/#findComment-1028754 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.