Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 制作HTML目录列表_Php_Database_Forms_List_Html Lists - Fatal编程技术网

Php 制作HTML目录列表

Php 制作HTML目录列表,php,database,forms,list,html-lists,Php,Database,Forms,List,Html Lists,我的网站上有一个表单,用户可以在其中输入文章的链接 到目前为止。。。当一个链接被提交时,我能够获得该链接,将其发布到目标html页面 然而。。。如果提交了另一个链接,它将删除第一个链接 我想链接到'堆栈',并使目标(目录)页(目前是一个html页面)列表 我不知道如何做到这一点。如有任何建议或示例,将不胜感激 我已经包括了一个非常精简版本的所有三页 1)表格 类型 正文{上页边距:20px;左页边距:20px;} .fieldHeader{字体系列:Arial,Helvetica,无衬线;字体

我的网站上有一个表单,用户可以在其中输入文章的链接

到目前为止。。。当一个链接被提交时,我能够获得该链接,将其发布到目标html页面

然而。。。如果提交了另一个链接,它将删除第一个链接

我想链接到'堆栈',并使目标(目录)页(目前是一个html页面)列表

我不知道如何做到这一点。如有任何建议或示例,将不胜感激

我已经包括了一个非常精简版本的所有三页

1)表格


类型
正文{上页边距:20px;左页边距:20px;}
.fieldHeader{字体系列:Arial,Helvetica,无衬线;字体大小:12pt;}
.articleURL{页边距顶部:10px;宽度:700px;高度:25px;}
.btnWrap{页边距顶端:20px;}
.postButton{cursor:pointer;}
输入文章链接:
  • 上载PHP(缓冲区)页面

    
    上传URL
    正文{上页边距:20px;左页边距:20px;}
    
  • 3.)目标HTML“目录列表”页面

        <!DOCTYPE html>
        <html>
        <head>
        <title>urlDirectory</title>
    
        <style>body{margin-top:20px; margin-left:20px;}</style>
    
        </head>
        <body>
        Sumbitted URL's should be listed here:
        </body>
        </html>
    
    
    URL目录
    正文{上页边距:20px;左页边距:20px;}
    此处应列出Sumbited URL:
    

    PS:我甚至不需要中间的php“缓冲区”页面。到目前为止,我对这类事情的了解有限。如果我不需要它,并且可以跳过该页面来满足我的需要,请给出建议。

    您可以使用PHP编写文件并使用
    urlDirectory.html
    作为模板来完成此操作。您只需更改php文件:

    urlUpload.php

    <?php
    
    function saveUrl($url, $template, $tag)
    {
        // If template is invalid, return
        if (!file_exists($template)) {
            return false;
        }
    
        // Remove whitespace from URL
        $url = trim($url);
    
        // Ignore invalid urls
        if (!filter_var($url, FILTER_VALIDATE_URL)) {
            return true;
        }
    
        // Read template into array
        $html = file($template);
    
        foreach ($html as &$line) {
            // Look for the tag, we will add our new URL directly before this tag, use
            // preg_match incase the tag is preceded or followed by some other text
            if (preg_match("/(.*)?(" . preg_quote($tag, '/') . ")(.*)?/", $line, $matches)) {
                // Create line for URL
                $urlLine = '<p>' . htmlspecialchars($_POST['articleURL']) . '</p>' . PHP_EOL;
    
                // Handle lines that just contain body and lines that have text before body
                $line = $matches[1] == $tag ? $urlLine . $matches[1] : $matches[1] . $urlLine . $matches[2];
    
                // If we have text after body add that too
                if (isset($matches[3])) {
                    $line .= $matches[3];
                }
    
                // Don't process any more lines
                break;
            }
        }
    
        // Save file
        return file_put_contents($template, implode('', $html));
    }
    
    $template = 'urlDirectory.html';
    
    $result = saveUrl($_POST['articleURL'], $template, '</body>');
    
    // Output to browser
    echo $result ? file_get_contents($template) : 'Template error';
    

    您是将这些值存储在数据库中还是只想添加到html文件中的列表中?没有sjdaw。不存储在数据库中。只想使用表单提交在html文件中生成列表。谢谢sjdaws。我有点困惑,新的php应该去哪里?我从问题中的3个不同页面开始。在你的例子中。。。您的示例会有多少个?抱歉,您的表单很好,我的答案分别替换了
    urlUpload.php
    urlDirectory.html
    。好吧,我想我只是感到困惑,因为urlUpload文件看起来与现在的更改相同。是的,唯一的区别是我删除了占位符。好的。祈求好运,给我一个机会。我会回来报到的。非常感谢。
        <!DOCTYPE html>
        <html>
        <head>
        <title>urlDirectory</title>
    
        <style>body{margin-top:20px; margin-left:20px;}</style>
    
        </head>
        <body>
        Sumbitted URL's should be listed here:
        </body>
        </html>
    
    <?php
    
    function saveUrl($url, $template, $tag)
    {
        // If template is invalid, return
        if (!file_exists($template)) {
            return false;
        }
    
        // Remove whitespace from URL
        $url = trim($url);
    
        // Ignore invalid urls
        if (!filter_var($url, FILTER_VALIDATE_URL)) {
            return true;
        }
    
        // Read template into array
        $html = file($template);
    
        foreach ($html as &$line) {
            // Look for the tag, we will add our new URL directly before this tag, use
            // preg_match incase the tag is preceded or followed by some other text
            if (preg_match("/(.*)?(" . preg_quote($tag, '/') . ")(.*)?/", $line, $matches)) {
                // Create line for URL
                $urlLine = '<p>' . htmlspecialchars($_POST['articleURL']) . '</p>' . PHP_EOL;
    
                // Handle lines that just contain body and lines that have text before body
                $line = $matches[1] == $tag ? $urlLine . $matches[1] : $matches[1] . $urlLine . $matches[2];
    
                // If we have text after body add that too
                if (isset($matches[3])) {
                    $line .= $matches[3];
                }
    
                // Don't process any more lines
                break;
            }
        }
    
        // Save file
        return file_put_contents($template, implode('', $html));
    }
    
    $template = 'urlDirectory.html';
    
    $result = saveUrl($_POST['articleURL'], $template, '</body>');
    
    // Output to browser
    echo $result ? file_get_contents($template) : 'Template error';