Link to home
Start Free TrialLog in
Avatar of TamHinh

asked on

How to limit insert keyword

I have a form as below:

<input type="text" id="keywords" name="keywords" class="text" size="20" />

Open in new window

I want when user input keywords separated by a comma as shown below:

nature, index, luxury, test1, test2, ..... test60

Open in new window

for example the user put 60 keywords, But I only get a maximum of 50 key words, how to?
Avatar of Rick Hobbs
Rick Hobbs
Flag of United States of America image

What is max_input_vars in php.ini set to?
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TamHinh


If I want to limit the maximum number of characters of a keyword, how to? for example, each input keywords only have a maximum of 20 characters
Thanks for points. To limit the length of accepted keywords you can use this:

if (isset($_POST['submit'])){
  $kw = $_POST['keywords'];
  $kw = preg_replace("/\s+/", " ", $kw);
  $kwArr = explode(' ', $kw);
  $output = array_slice($kwArr, 5, count($kwArr));
  $output = array_diff($kwArr, $output);
  for($i = 0; $i<count($output); $i++){
    if (strlen($output[$i]) <= 20){
      $result[] = $output[$i];
  $keywords = implode(', ', $result);
  echo $keywords;

Open in new window