|
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]
|