Jump to content

Recommended Posts

How to check if the input words are seperated by comma.For example i have a field and i want to enter some keywords.How to check if they are seperated by comma.I know that it must be done with regular expresions but i dont know how to use them exactly.Will check the php manual,but if you have any suggestions please help :)
Link to comment
https://forums.phpfreaks.com/topic/24245-comma-seperated-input/
Share on other sites

Here is one way, i assume you want to split the string if it is comma-separated:
[code]

<?php

$s = $_GET['s']; // search string or whatever

$string = explode(",",$s);
if(count($string)>1)
{
  echo "comma exists in <b>$s</b>, separated as:<br /><pre>";
  print_r($string);
  echo "</pre>";
}
else
{
  echo "no commas found in <b>$s</b>";
}

?>

[/code]
Link to comment
https://forums.phpfreaks.com/topic/24245-comma-seperated-input/#findComment-110188
Share on other sites

[quote author=feri_soft link=topic=111808.msg453303#msg453303 date=1161112159]
No,i dont want to split it i just want to be shure that the user adds to the db something like

asdasd,asdasd,asdasd,asdas not asdasd-asdasd-asdasd or sdasdasd/asdasdasd/asdasd or asdasdasdasdasdasdasdasd
[/quote]

Even if you don't want the split results, Alpine's code will still tell you what you want to know

EDIT: but how do you know "asdasdasdasdasdasdasdasd" is wrong? - the user may just want to enter a single item
Link to comment
https://forums.phpfreaks.com/topic/24245-comma-seperated-input/#findComment-110240
Share on other sites

Can the data values include non alphanumeric characters? If not just use regular expressions to replace non-alphanumeric characters to commas. however, if the users can enter data value with non-alphanumeric characters, then you cannot do what you are asking because you wouldn't be able to determine if the user is using "-" as a delimiter or as part of the data.
Link to comment
https://forums.phpfreaks.com/topic/24245-comma-seperated-input/#findComment-112049
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.