You are here: Regular expression to compare two variables similar to SQL: field LIKE 'value%' « PHP Programming Language « IT news, forums, messages
Regular expression to compare two variables similar to SQL: field LIKE 'value%'

Posted by bissatch on 10/18/05 13:54

I am trying to compare two variable but using regular expression:

$access = "glasgow"

$areaid = "glasgow-westend-byers_rd"

using the two variables, I would like the areaid variable to be
compared with the access variable. the regular expression function will
return true if $access matches the start of $areaid. So the two above
would return true

The following would also return true:

$access = "glasgow-westend"

$areaid = "glasgow-westend-byers_rd"

or

$areaid = "glasgow-westend-greatwestern_rd"

However, the following should return false though:

$access = "glasgow"

$areaid = "stirling-glasgow_rd"

Although the value for $access, 'glasgow', appears in the $areaid it
does not appear at the start.


If I were to do this in SQL it would be something like:

$select = "SELECT * FROM areas WHERE areaid LIKE '" . $access . '%"

Note the use of '%' at the end of the compare LIKE field

Unfortunetely I have never been able to properly get my head round
regular expressions.

Any help?

Cheers, burnsy

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация