我有以下代码:PHP变量太多写
require("class.XMLHttpRequest.php");
function hot($news){
$url="https://localhost/search.aspx?search=".$news."";
$ajax=new XMLHttpRequest();
$ajax->setRequestHeader("Cookie","Cookie: host");
$ajax->open("GET",$url,true);
$ajax->send(null);
if($ajax->status==200){
$rHeader=$ajax->getResponseHeader("Set-Cookie");
if(substr_count($rHeader, "Present!")>0) { return true; }
}else{ return false; }
}
$content1= hot("britney") ? "britney found" : "";
$content2= hot("gaga") ? "gaga found" : "";
$content3= hot("carol") ? "carol found" : "";
$filename = 'result.txt';
$handle = fopen($filename, 'a');
fwrite($handle, "$Content1\r\n");
fwrite($handle, "$Content2\r\n");
fwrite($handle, "$Content3\r\n");
fwrite($handle, "$Content4\r\n");
fclose($handle);
我想缩短脚本cuz我有很多$ ContentN变量 也许类似的foreach?
我在这两种情况下都有空格 – adam 2010-09-30 13:05:31
是的,对不起。但在他的情况下,测试更容易。 'if(hot($ celebrity))fwrite($ handle,“{$ celebrity} found \ r \ n”);'不再有空格。 – 2010-09-30 13:07:51
如果你不想空行,它更容易...更新我的答案。 (谢谢Loïc) – Mischa 2010-09-30 13:15:41