Jump to content

php and mysql REGEXP curly braces and max characters


fohanlon

Recommended Posts

Hi Guys

 

I am having trouble with a mysql regexp expression called through php.  I am not sure but I suspect its to do with the {} in the mysql code and PHP parsing them incorrectly.

 

Here is my code snippet:

 

$q = mysql_real_escape_string($_POST['keyword']);

$limit = 10;  //limit number of responses from dictionary

$remainder = 11 - strlen($q);

if ($q)

{

$qy = "SELECT * FROM dict_list WHERE UCASE(word) <> UCASE('$q') AND (word REGEXP '^$q.{$remainder}') LIMIT $limit";

$query = mysql_query($qy);

 

...

 

What I want to do is this:

 

a user types in a word.  I then want to query a dictionary table called dict_list for all matches of the this word up to 11 characters max.

 

Example:

 

if $q was the word aero then the response would be all words beginning with aero and up to a max of 11 characters.  That is why IU thought I could calculate length of $q and from this get the $remainder = 11 - strlen($q) then in the REGEXP use .{$remainder} but when testing if I echo out the query $qy the curly braces will not show on screen.

 

Any help would be greatly appreciated.

 

I hope this is posted in correct location. Apologies if not.

 

Thanks,

 

Fergal.

 

It would but what about the words that are not 11 characters.  11 is the max length and I want to return any words from string length of $q up to 11 characters that begin with $q.  I can do it using LIKE but thought I could get away with using REGEXP instead.

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.