PHP输出链接


PHP output link

我下面有这个函数。它输出Mysql数据库的每一行。每一行都是一个文件的路径。

例如

/Volumes/02_SERVER/GRADE/GRADE_10/Test Me/978079 G10 English/downloads/revision-tests

它运行良好。但我想要的是让它可以链接。

我试过这种东西:

echo "<a file='" . $o . "' ></a>";

但它不起作用

所有代码:

<?php
    require_once 'db.php';
    // Output HTML formats
    $html = '<tr>';
    $html .= '<td class="small">nameString</td>';
    $html .= '</tr>';
    // Get the Search
    $search_string = preg_replace("/_-[^A-Za-z0-9]/", " ", $_POST['query']);
    $search_string = $test_db->real_escape_string($search_string);
    // Check if length is more than 1 character
    if (strlen($search_string) >= 1 && $search_string !== ' ') {
        //Insert Time Stamp
        $query = 'SELECT * FROM live_table WHERE name LIKE "%' . $search_string . '%"';
        //Timestamp entry of search for later display
        $time_entry = $test_db->query($time);
        //Count how many times a query occurs
        $query_count = $test_db->query($query_count);
        // Do the search
        $result = $test_db->query($query);
        while ($results = $result->fetch_array()) {
            $result_array[] = $results;
        }
        // Check for results
        if (isset($result_array)) {
            foreach ($result_array as $result) {
                // Output strings and highlight the matches
                $d_name = preg_replace("/" . $search_string . "/i", " <b>" . $search_string . "</b>", $result['name']);
                $d_comp = $result['company'];
                // Replace the items into above HTML
                $o = str_replace('nameString', $d_name, $html);
                // Output it
                echo ($o);
            }
        } else {
            // Replace for no results
            $o = str_replace('nameString', '<span class="label label-danger">No Data Found</span>', $html);
            // Output
            echo($o);
        }
    }
?>

请给出如下路径(http://localhost/pagination/)这是你的锚标签,这样你包含的数据库就可以访问,并且你得到了正确的resutlt。

HTML锚点中本地链接的格式是

<a href='file://filepath/file.ext'>Description </a>

在您的PHP代码中,更改

echo($o);

 echo("<a href='file://$o'>$o</a>");