?
Solved

How to limit insert keyword

Posted on 2013-01-01
4
Medium Priority
?
381 Views
Last Modified: 2013-01-01
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?
0
Comment
Question by:TamHinh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 22

Expert Comment

by:Rick Hobbs
ID: 38734300
What is max_input_vars in php.ini set to?
0
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 2000 total points
ID: 38734334
I'm not sure to understand, so let me summarize:
you have an input type='text' where a user can put an unlimited number of keywords: you want to grab these keywords only up to 50 and have them separated by a comme. If this is the case, you can try this:

<?php

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);
  $keywords = implode(', ', $output);
  echo $keywords;
}

echo "<form method='post'>";
echo "<input type='text' name='keywords' value='' />";
echo "<input type='submit' name='submit' value='Submit' />";
echo "</form>";

Open in new window


Cheers
0
 

Author Comment

by:TamHinh
ID: 38734349
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
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 38734495
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

Cheers
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question