-1

hi i use this code to find a file on directory specified. this works but i want that when i click on resoutt it opens in new tab

code is:

<?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);
?>

when i use

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

this shows:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in    /home/u688698883/public_html/search/ss.php on line 8
SynsMasTer
  • 11
  • 4
  • If you just want your `$file` openned in the new tab, add `target="_blank"` to your `a` element. – Hieu Le Jul 24 '13 at 01:57

1 Answers1

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

This opens a new tab / window depending on user preference. Please search before posting.

Open link in new tab or window

In your case:

<?php
  echo "<a href='$dir/$file' target = '_blank'>$file</a>";
?>
Community
  • 1
  • 1
Chris
  • 1
  • 1
  • Common PHP knowledge says you need to escape the key or use single quotations. – Chris Jul 24 '13 at 02:07
  • it shows this error "Parse error: syntax error, unexpected '<' in /home/u688698883/public_html/search/ss.php on line 8" – SynsMasTer Jul 24 '13 at 02:24