Added new Algorithm to script, somethings gone wrong?

Discussion in 'PHP' started by ojsimon, Feb 3, 2008.

  1. #1
    Hi
    On my video site this is the code that merges the results and prepares them for displaying. <?
    function getall($searchterms) {
    <?
    function getall($searchterms) {
    	require("yt.php");
    	require("gv.php");
    	require("dm.php");
    	require("mc.php");
    	
    	$yt = yt($searchterms);
    	$gv = gv($searchterms);
    	$dm = dm($searchterms);
    	$mc = mc($searchterms);
    	
    	$all = array_merge($yt,$gv,$dm,$mc);
    	if(count($all)) {
    		include_once "latest.php";
    		updatelatest(str_replace("+","-",$searchterms));	
    	}
    	$bannedwords = "bannedwords.txt";
    	$fp = fopen($bannedwords, "r");
    	$wordstmp = fread($fp, filesize($bannedwords));
    	fclose($fp);
    	$words = explode("\n",$wordstmp);
    	$words = array_map("strtolower",$words);
    	
    	foreach($all as $index=>$arr) {
    		$arrtitle = $arr['title'];
    		foreach($words as $index2=>$word) {
    			if(strstr(strtolower($arrtitle),strtolower(str_replace("\n","",str_replace("\r","",$word))))) {
    				unset($all[$index]);
    				break;	
    			}
    		}
    	}
    	
    	srand((float)microtime() * 1000000);
    	shuffle($all);
    	foreach($all as $j=>$k) {
    		if(!trim($k['title'])||!trim($k['link']))
    			unset($all[$j]);	
    	}
    
    	return $all;	
    }
    
    ?>
    Code (markup):

    At the moment this shuffles the results so they are in random order, i want to make them in order of relevance so i found this algorythym
    usort($multifeed,'funnySort');
    
    function funnySort($a,$b)
    {
        // assign numerical value so we can sort on 
            // whether "term" is in title or content or neither
    
        $term = 'funny';
    
        $x = 0;    
        if (stripos($a->get_title(),$term))
            $x = 2;
        elseif (stripos($a->get_content(),$term))
            $x = 1;
    
        $y = 0;    
        if (stripos($b->get_title(),$term))
            $y = 2;
        elseif (stripos($b->get_content(),$term))
            $y = 1;
    
        return $x <= $y
    }
    Code (markup):
    I have tried just putting this in the place of shuffle and changing the variables, but it doesnt work, how can i make this work? any help is appreciated.

    Thanks
     
    ojsimon, Feb 3, 2008 IP
  2. ojsimon

    ojsimon Active Member

    Messages:
    459
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    Please help?
     
    ojsimon, Feb 4, 2008 IP