2013-07-24 35 views
-1

您好我使用此代码在指定的目录中查找文件。这个工作,但我想,当我在resoutt双击它,在新标签页中打开我想要在新标签页中打开搜索结果

代码:

<?php 
$dir = 'ups'; 
$exclude = array('.','..','.htaccess'); 
$q = (isset($_GET['q']))? strtolower($_GET['q']) : ''; 
$res = opendir($dir); 
while(false!== ($file = readdir($res))) { 
if(strpos(strtolower($file),$q)!== false &&!in_array($file,$exclude)) { 
echo "<a href='$dir/$file'>$file</a>"; 
echo "<br>"; 
} 
} 
closedir($res); 
?> 

当我使用

<?php 
echo "<a href='$dir/$file'>$file target = "_blank"</a>"; 
?> 

这表明:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/u688698883/public_html/search/ss.php on line 8 
+0

如果你只是想你'在新标签openned $ file',加上'目标= “_空白”'你'了'元素。 –

回答

0
<a href = "something.php" target = "_blank"> 

这会根据用户打开一个新标签页/窗口偏爱。发帖前请先搜索。

Open link in new tab or window

你的情况:

<?php 
    echo "<a href='$dir/$file' target = '_blank'>$file</a>"; 
?> 
+0

它不起作用 – SynsMasTer

+0

常见的PHP知识说你需要转义密钥或使用单引号。 Chris

+0

它不起作用 – SynsMasTer

相关问题