Jump to content

Restrict array size / length ??


doa24uk

Recommended Posts

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?

Link to comment
Share on other sites

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);

Link to comment
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.