I found the following code which removes everything from a php var other than the letters and numbers, perfect!
$string = "remove ever^&thing but *&^*&%£ letters & numbers*&^*";
$cleansedstring = preg_replace('#\W#', '', $string);
echo $cleansedstring;
But I want to query a column in mysql using the same rule. The aim is to kinda remove all ampersands, apostrophes, hyphens etc from the equation.
Right now I use some ugly REPLACE statements!
AND Replace(Replace(Replace(Replace(Replace(MYColumn, '&', ''), '-', ''), ' ', ''), '(', ''), ')', '') =
I would like a bullet proof query going forward that only looks at numbers and letters!
:)
EDIT: I guess I should explain my problem further, perhaps one of you can suggest something else....
I generate links across my website by pulling out long company names and cleaning them up for a seo friendly URLs. So say we have "Bill & Ben's Flower Pot/Garden Service" my eventual URL to their page looks like /bill-bens-flower-pot-garden-service.htm
That URL is a rewritten URL so the actual page is like company.php?name=bill-bens-flower-pot-garden-service
I need to grab "name" and query the database to return their company details. But getting:
bill-bens-flower-pot-garden-service
to return the details of:
Bill & Ben's Flower Pot/Garden Service
Isn't always bullet proof it seems.
It just feels like my code is a little messy in how many replaces I'm doing all over the place. My theory was to just strip all non letters and numeric data out and compare the strings that way:
WHERE Company = 'billbensflowerpotgardenservice' - but I can't seem to do that on the field name itself?
Any suggestions!