2012-05-15 5 views
0
function findit($gbq, $kwords){ 

$original_file = file_get_contents($gbq); 

$keytar = $kwords; 
$ckeytar = strtoupper($keytar); 
$okeytar = strtolower($keytar); 

$arrit = array(
    "original" => $keytar, 
    "ocap" => $ckeytar, 
    "olow" => $okeytar, 
); 

if(strpos($original_file, $arrit['original']) == true) { 
    $fp = fopen("linkter.html", 'a'); 
    fwrite($fp, "<a href='" . $gbq . "' style='color:orange;'>" . $gbq . "</a>"); 
    fclose($fp); 
} 
elseif(strpos($original_file, $arrit['ocap']) == true) { 
    $fp = fopen("linkter.html", 'a'); 
    fwrite($fp, "<a href='" . $gbq . "' style='color:red;'>" . $gbq . "</a>"); 
    fclose($fp); 
} 
elseif(strpos($original_file, $arrit['olow']) == true) { 
    $fp = fopen("linkter.html", 'a'); 
    fwrite($fp, "<a href='" . $gbq . "' style='color:green;'>" . $gbq . "</a>"); 
    fclose($fp); 
} 
else{ 
    echo "String not found"; 
} 

}strpos 어떤 이유로 빈 구분

는 두 번째 조건 (은 $ arrit [ 'OCAP'] 하나)에 빈 구분자가 말했다. 대신 strpos()stripos()를 사용하여 일을 단순화하면 다음과 같이

+0

'$ arrit [ 'ocap']'가 실제로 값을 가지고 있는지 확인 했습니까? –

+0

무엇을 의미합니까? –

+0

저는 PHP를 자주 사용하지 않으므로 이해하지 못해서 미안합니다. –

답변

0

은 어떻게됩니까

는 좀 다른 답변을 읽었습니다,하지만 난 작품 하나를 발견하지 않았습니다 (또는 내가 생각 일 것이다) :

function findit($gbq, $kwords) 
{ 
    $original_file = file_get_contents($gbq); 

    if (stripos($original_file, $kwords) !== false) 
    { 
     $fp = fopen("linkter.html", 'a'); 
     fwrite($fp, "<a href='" . $gbq . "' style='color:orange;'>" . $gbq . "</a>"); 
     fclose($fp); 
    } 
    else 
    { 
     echo "String not found"; 
    } 
} 
관련 문제