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?
 
Chris StanyonCommented:
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
 
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 StanyonCommented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
lawrence_devAuthor Commented:
Chris,
Please advise how to correctly structure.  Thanks for your help!
0
 
Chris StanyonCommented:
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
 
lawrence_devAuthor Commented:
Thanks Chris!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.