Jump to content

Comma seperated input


feri_soft

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.