How do I fix this strpos statement?

How do I fix the STRPOS statement?  What am I doing wrong here?


if ($Brand="PREMIUM POWER" AND (strpos($ModelArray,'Latitude'|'Vostro'|'ChemBook'|'Inspiron'|'JetBook'|'Precision'|'Studio'|'XPS')) !== false) {
    $NewBrand="Dell";
    }  else if ($Brand="PREMIUM POWER" AND (strpos($ModelArray,'ThinkPad')) !== false) {
    $NewBrand="IBM";
	}  else if ($Brand="PREMIUM POWER" AND (strpos($ModelArray,'Presario'|'Pavilion')) !== false) {
    $NewBrand="HP";
    } else {
	$NewBrand=$row5[Manufacturer];
	}

Open in new window

lawrence_devAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marco GasiFreelancerCommented:
Line 3 must be
else if ($Brand="PREMIUM POWER" AND (strpos($ModelArray,'ThinkPad') !== false)) {

Open in new window

and line 5 must be:
}  else if ($Brand="PREMIUM POWER" AND (strpos($ModelArray,'Presario'|'Pavilion') !== false)) {

Open in new window

0
Chris StanyonWebDevCommented:
There's a lot wrong with your code.

Firstly, a single = is an assignment - for compasrison your need a double ==

AND in your if statement should be &&

You can't use a single strpos call for multiple words - you need to loop through them. Create an array and loop through them one by one.
0
lawrence_devAuthor Commented:
Chris,
Please advise how to correctly structure.  Thanks for your help!
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Chris StanyonWebDevCommented:
No worries. can you show me what's in $modelarray. Is it actually an array as the name suggests
0
lawrence_devAuthor Commented:
It is really not an 'array' per se.   It is pipe delimited.  Here it is:

ThinkPad i1700|ThinkPad i1720|ThinkPad i1721 etc

Thanks for your help!!
0
Chris StanyonWebDevCommented:
Have a look through this. You can probably streamline it, but hopefully you'll get the general idea:

$NewBrand = null;

if ($Brand=="PREMIUM POWER") {
	if (is_null($NewBrand)) {
		$brandList = array('Latitude', 'Vostro','ChemBook','Inspiron','JetBook','Precision','Studio','XPS');
		foreach ($brandList as $brand) {
			if (strpos($ModelArray, $brand) !== false) {
				$NewBrand = "Dell";	
				break;		
			}
		}
	}
	
	if (is_null($NewBrand)) {
		$brandList = array('ThinkPad');
		foreach ($brandList as $brand) {
			if (strpos($ModelArray, $brand) !== false) {
				$NewBrand = "IBM";	
				break;		
			}
		}
	}
		
	if (is_null($NewBrand)) {
		$brandList = array('Presario','Pavilion');
		foreach ($brandList as $brand) {
			if (strpos($ModelArray, $brand) !== false) {
				$NewBrand = "HP";	
				break;		
			}
		}
	}
}	

if (is_null($NewBrand)) {
	$NewBrand = $row5[Manufacturer];
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lawrence_devAuthor Commented:
Thanks Chris!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.