Jump to content

need help debugging function...


The14thGOD

Recommended Posts

So I have a really complicated search/filter system going on here and am trying to get a couple items to work. For some reason they are not. The only thing I can see that is common between the two not working examples is the & character.

 

There are multiple practice areas (the [XX] is there for tying specialties to practice areas which has to be editable by client). Here I am just trying to get the practice area and not anything else. It should be pretty straight forward. I had it working before without the brackets so not sure why it's not working now. Should be pretty straight forward.

<?php
/*
Example print_r of $cats = Array ( [0] => [CL]Commercial Litigation [1] => [PL]Product Liability/Mass Tort [2] => [HC]Health Care Law & Consulting [3] => [LE]Labor & Employment [4] => [bG]Business Group )

Example $practice_areas = Commercial Litigation| Health Care Law & Consulting

Working $ps examples = [CL] || [PL] || [bG]
Not-working $ps examples = [HC] || [LE]
*/
function checkPracticeAreas2($practice_areas,$cats){
	$member = false;
	//$practice_areas = str_replace('&','&#038;',$practice_areas);
	$practice_areas = str_replace('[L]','',$practice_areas);//remove leader attr
	$practice_areas = explode('|',$practice_areas);

	//find which practice area
	$ps = $_GET['ps'];
	$plus = stripos($ps,'+');//if specialty is present, just get the practice_area intials 
	if($plus !== false){
		$xpld = explode('+',$ps);
		$ps = $xpld[0];
	}
	for($i=0;$i<sizeof($cats);$i++){
		$isAbbr = stripos($cats[$i],urldecode($ps));
		if($isAbbr !== false){
			$the_practice = substr($cats[$i],4);
			break;
		}
	}

	for($i=0;$i<sizeof($practice_areas);$i++){
		$isPracticeArea = stripos($practice_areas[$i],$the_practice);
		if($isPracticeArea !== false){
			$member = true;
			break;
		}
	}
	return $member;
}
?>

 

I don't know if I've started at this for too long or what I'm missing...but I'm just running in circles.

 

Thanks for any and all help,

Justin

Link to comment
https://forums.phpfreaks.com/topic/244555-need-help-debugging-function/
Share on other sites

not sure I get what you're doing here...

 

if, as you say,  $practice_areas = "Commercial Litigation| Health Care Law & Consulting"

 

why are you doing this if there is no [L] in $practice_areas ?

 

$practice_areas = str_replace('[L]','',$practice_areas);

 

Some people have [L] in front of the practice area because they are the group leader so it just runs automatically to make sure it's not in the string. The example I gave just happened to not have it. Sorry, should of removed it to avoid confusion.

 

Basically I'm calling the function:

 

$member = checkPracticeAreas2($practice_areas,$cats);

If it's returns true I do some other stuff to it.

For some reason whenever [HC] or [LE] is to be matched it always returns false. (It should return true 5-30 times depending on category).

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.