i have a field in my database with numbers like this.......

,27,,277,,4277,,677,,678,,6688,,8754,,123478,

each number was updated (added) like this .. ,27,

all numbers updated are unique,

when i try to match ,27,

i get ,27, ,277, ,4277, not just ,27,

my code is like this...

$id = 27

$string = ",27,,277,,4277,,677,,678,,6688,,8754,,123478,"

$getid = preg_match("/$id/", $string);

please help :)

try: $getid = preg_match('/\b' . $id . '\b/', $string); Or if you prefer to use the double quotes (like you posted), be sure to escape the backslash: $getid = preg_match("/\\b$id\\b/", $string);

try: $getid = preg_match('/\b' . $id . '\b/', $string); Or if you prefer to use the double quotes (like you posted), be sure to escape the backslash: $getid = preg_match("/\\b$id\\b/", $string);

this seems to work.....,

$id = 27 $string = ",27,,277,,4277,,677,,678,,6688,,8754,,123478," 

$getid = preg_match("/,$id,/", $string);


// but is it correct coding with the commas?? 

("/,$id,/", $string)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.