I am currently working on a website that uses PHP to search a database for a part number. A part of the code uses regular expressions to make it easier to search the text file for the appropriate match. However, I am stuck using a method that seems overburdensome, but I cannot find a means of doing what I want with regular expressions by searching google and other places for php help. So here I am.
The code I am writing now, looks like this:
This will continue for a very long time, egt and cht are types of gauges that are being searched for, and there are 4 different number sets, each with 5 different sizes, each containing about 15 or so gauge types. The work would be outrageous if I had to continue in this fashion.PHP Code:if ( ( $number == 1 ) && ( $size == "2inch" ) )
{
function type1($type1)
{
return (eregi('2"', $type1));
}
if ( $type == "cht" )
{
function type2($type2)
{
return (eregi("cht", $type2));
}
}
elseif ($type == "egt" )
{
function type2($type2)
{
return (eregi("egt", $type2));
}
}
}
What I want to be able to do instead, would be to directly input the type variable into the regular expression search, but when i try to apply this method it doesn't work.
The conceptual method looks like this:
Is there any way to implement a variable into a regular expression, like I want above. I have tried putting it inside of quotation marks and apostrophes as well.PHP Code:if ( ( $number == 1 ) && ( $size == "2inch" ) )
{
function type1($type1)
{
return (eregi('2"', $type1));
}
function type2($type2)
{
return (eregi($type, $type2));
}
}
Thanks for any help





Bookmarks