0

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 :)

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by luke noob
0

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);

Edited by hielo: n/a

0

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)

Edited by luke noob: forgot code tags

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.