Solved

How to limit insert keyword

Posted on 2013-01-01
4
379 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 500 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 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