Welcome Guest, Not a member yet? Register   Sign In
:( Think im going to have to use Regular Expressions :(
#6

[eluser]BrianDHall[/eluser]
You are being too hard on yourself - regex in this instance is super easy to do, I will show. Great resource for future reference: http://www.regular-expressions.info

I highly recommend you have an IDE or text editor that offers regular expression search/replace so you can test things there to see how they work before trying to mess around with PHP functions.

Code:
$dirty = 'partABC!-# 12:/}{\\34';

function part_degreaser($dirty)
{

$pattern = '/' . '[^\w]' . '/';
$clean = strtolower(preg_replace($pattern, '', $dirty));

// $clean is now partabc1234

return $clean
}

The pattern is extremely simple here - it says "if there is anything other than a regular word character (alphanumeric), kill it!".

You can run this exact same function on search string input for part numbers, and before loading part information into the database.

You just have to make sure before-hand that you _really_ don't care about anything other than alphanumeric part numbers. If "abc123" is different than "ab-c123" is different than "abc-12-3" - then you need to store the original unsanitized part number for disambiguation. You still run the same query to pull results, but you know you might have multiple results - so you display them all to the user and let them figure out what they really wanted.


Messages In This Thread
:( Think im going to have to use Regular Expressions :( - by El Forum - 10-22-2009, 09:18 AM
:( Think im going to have to use Regular Expressions :( - by El Forum - 10-22-2009, 10:01 AM
:( Think im going to have to use Regular Expressions :( - by El Forum - 10-22-2009, 12:22 PM
:( Think im going to have to use Regular Expressions :( - by El Forum - 10-22-2009, 12:42 PM
:( Think im going to have to use Regular Expressions :( - by El Forum - 10-22-2009, 02:17 PM
:( Think im going to have to use Regular Expressions :( - by El Forum - 10-22-2009, 03:57 PM
:( Think im going to have to use Regular Expressions :( - by El Forum - 10-22-2009, 04:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB