Re: expanding inside quotes problem

From: Date: Tue, 07 Nov 2000 11:31:36 +0000
Subject: Re: expanding inside quotes problem
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-24083@lists.php.net to get a copy of this message
> On Tue, 07 Nov 2000, Andrew Threlfall wrote: > > I've a problem with the folowing line > > > > $results = mysql_query("SELECT * FROM group WHERE postcode REGEXP > > '^$query[:digit:]+.*'", $db) > > > > when run I get: > > "Parse error: parse error, expecting T_STRING' or > > T_VARIABLE' or > > `T_NUM_STRING' " > > > > I think the problem is that php is treating the square brackets as a regular > > expression, and attempting to expand it(?). I can stop this by using single > > quotes, but then the variable in the string will not be expanded. > > > > I'm not sure what to escape in order that the query get passed correctly. > > > > Try isolating the variable from the string, thus: > > $query = > "SELECT * FROM group WHERE postcode REGEXP > '^" . $query . "[:digit:]+.*'"; > $results = mysql_query($query,$db); > Yup, taking the variable out and concatinating it seems to work. Thanks. Philip Hallstrom also suggested something like: "blah blah {$query}[blahblah] blah blah" ...might work. But I've not tried it. -- Andrew

« previous php.general (#24083) next »