我正在尝试为制药网站创建新闻页面。
我创建了一篇新闻文章"创作"允许用户输入作者,描述和正文等信息的页面。
代码看起来像这样。
<html>
<body>
<style>
textarea
{
resize: none;
}
</style>
<form action="foo.php" method="post">
<label for="textarea">Title:</label>
<p></p>
<textarea rows="1" cols="100" name="title"></textarea>
<br></br>
<label for="textarea">Author:</label>
<p></p>
<textarea rows="1" cols="100" name="author"></textarea>
<br></br>
<label for="textarea">Description:</label>
<p></p>
<textarea rows="15" cols="100" name="desc"></textarea>
<br></br>
<label for="textarea">Body:</label>
<p></p>
<textarea rows="15" cols="100" name="body"></textarea>
<br></br>
<p><input type="submit" name="submit" value="Submit" /></p>
</form>
</body>
</html>
该信息被发送到foo.php,我希望foo.php动态创建一个div,其中包含标题,作者,发布日期和描述。然后这个div将有一个&#34; Read More&#34;显示实际文章的按钮或&#34; body&#34;在这种情况下。
然后我想将这个div插入一个单独的html页面。换句话说,每次创建新文章的用户单击提交按钮时,信息都会被处理,添加到div元素,然后将div插入另一个html页面。
有没有办法做到这一点,或者一些示例新闻/文章教程解释了如何做到这一点?我一直在寻找几个小时,这个特定话题似乎没什么。我也尝试过这方面的事情,但这让我无处可去,经过3天多的努力想出来之后,我已经准备好掏出我的眼睛了。
<script>
<?php
foreach (glob("*.txt") as $filename)
{
$lines_array = file($filename);
$search_string_title = "Article_title";
$search_string_published = "Published";
$search_string_author = "Author";
$search_string_desc = "Description";
$search_string_body = "Body";
foreach($lines_array as $line)
{
if(strpos($line, $search_string_title) !== false)
{
list(,$title_str) = explode(":", $line);
}
if(strpos($line, $search_string_published) !== false)
{
list(,$published_str) = explode(":", $line);
}
if(strpos($line, $search_string_author) !== false)
{
list(,$author_str) = explode(":", $line);
}
if(strpos($line, $search_string_desc) !== false)
{
list(,$desc_str) = explode(":", $line);
}
if(strpos($line, $search_string_body) !== false)
{
list(,$body_str) = explode(":", $line);
}
}
$article_title = $title_str;
$published = $published_str;
$author = $author_str;
$desc = $desc_str;
$body = $body_str;
$news_content= array($article_title, $published, $author, $desc, $body);
}
?>
var news = <?php echo json_encode($news_content) ?>;
var title = news[0];
var published = news[1];
var author = news[2];
var desc = news[3];
var body = news[4];
var div = document.createElement("div");
div.style.width = "600px";
div.style.height = "600px";
div.style.background = "red";
div.style.color = "white";
var sHTML = '<div style="text-align:center; padding:15px; font-weight:bold;">' + title + "<br />" + "<br />" + "Published: " + published + "<br />" + "Author: " + author + "<br />" + "<br />" + desc + </div>';
div.innerHTML = sHTML;
div1.appendChild(div);
</script>
答案 0 :(得分:0)
听起来你需要一个数据库!
您可以将您发布的页面中的信息存储到数据库中。然后,foo.php将从数据库加载此信息。
使用PHP查看MySQL。两人互相配合得很好。如果您一般不熟悉数据库,我建议您遵循一些Microsoft Access数据库教程。通过Access,您可以轻松地查看数据在数据库中的保存方式。
答案 1 :(得分:0)
我会考虑将这些信息放入数据库中,在另一页上,让它从数据库表中提取记录并以这种方式填充div。
答案 2 :(得分:0)
您尝试做的事情听起来很像MVC
我这样做的方法是制作一个类似你所描述的页面,当我输入信息时,我会将数据发送到PHP脚本以将我的信息放入数据库(如MySQL) )。
在你希望显示div的页面上,我只需遍历我的数据库文章行,并让我的php回显你想要的那些div中的信息。