Page 1 of 1
Posting/Updating System - how to delete html section?
Posted: Fri Sep 28, 2007 7:15 am
by Sindarin
Okay, I am trying to create a simple news system for a site. Nothing complex, the layout is going to be all css.
Now what I need for it is a posting form page (for posting new posts) a news page (for viewing the news) and
a delete form page (for deleting any useless posts).
Now I have a postnew.php file which is a simple form with 3 fields and the php script writes those values in the "news.html" file.
Code: Select all
<?php
$from= $_POST['from'];
$title= $_POST['title'];
$content= $_POST['editor_1'];
//filename to write
$filename="news.html";
$handle = fopen($filename, 'a');
fwrite($handle, "<br>FROM <b>$from</b> : <i>$title</i> <br><br>");
fwrite($handle, "$content <br><br>");
echo "<center><a href='news.html'>News updated, click here to view the news page</a>"
?>
The news.html page simply displays all the news entries.
Now, how can I do it that the news are listed in a page (let's say deletepost.php) using php_include but have a delete button below them that can delete each individual entry?
Posted: Fri Sep 28, 2007 7:58 am
by John Cartwright
Is there any chance you can shift your storage medium to a database? Using text files seriously over complicates this problem.
Posted: Fri Sep 28, 2007 8:28 am
by Sindarin
I've thought of it but I don't know MySql and I also don't believe the web hosting company have a database installed on their end.
The goal is to be made very simple with php and flat files.
Actually I have thought if it would be possible to add some kind of identification tag to the start and end of each post and recognize this with php in order to remove individual posts. Just an idea...
Posted: Fri Sep 28, 2007 10:00 am
by phpdevuk
I did something similar a while back though it was stored in a database, basically I wrapped each news item in a container div and displayed a delete tick next to each one, when clicked that div and its contents were removed. The final HTML was then posted to a page which merely took hidden form fields containing the HTML and stored them. When ever an update was made or an item deleted the hidden form fields on the first page were either set to blank or contained the html for the new entry. You need a pretty good knowledge of javascript to do it but it works quite well.
Posted: Mon Oct 01, 2007 3:33 am
by Sindarin
Isn't there any functions to search for two strings and remove that particular piece between of them?
Posted: Mon Oct 01, 2007 3:45 am
by s.dot
Sindarin wrote:Isn't there any functions to search for two strings and remove that particular piece between of them?
strpos() for searching for a string within a string.
or usage of preg_match() (to search for the string(s)) and preg_replace() to replace content between the strings.
Posted: Mon Oct 08, 2007 7:41 am
by Sindarin
Gah, I am trying to figure this out, but no luck.
I am trying to create a simple uploader which the user can upload a file and write a title for the link.
The link (with the user defined title) is going to be added to an archives.php file through fwrite.
The target is, in case of an error to be able to delete a link.
I am making simple tests in order to learn about preg_replace but php spits out errors all the time,
The posts/links are going to be written into the archives.php in this way:
Code: Select all
<style>
.hid
{
visibility:hidden;
}
</style>
<div class="hid">post1</div>
<div><a href="interview-part1.zip">get the file here</a></div>
<div class="hid">end of post1</div>
<div class="hid">post2</div>
<div><a href="interview-part2.zip">get the file here</a></div>
<div class="hid">end of post2</div>
so if I want to delete post1, I'll have to execute this, right?:
Code: Select all
<?php
$post1='<div class="hid">post1</div>'
$post1end='<div class="hid">end of post1</div>'
$delete=''
echo preg_replace($post1, $post1end, $delete);
?>
Posted: Mon Oct 15, 2007 5:57 am
by Sindarin
Gah, I quit that way.
Is there a way to read and return all text files in a directory?
Like there are 2 text files
post1.txt contains:
post2.txt contains:
Code: Select all
<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/gR3cRdRhk6Q"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/gR3cRdRhk6Q" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>
So the php script returns a simple text and a youtube video ordered by their date of creation?
Posted: Mon Oct 15, 2007 4:40 pm
by phpdevuk
look at the php function readdir and possibley the fread function or similar file functions?
Posted: Mon Oct 15, 2007 5:53 pm
by Stryks
Sorry to jump back a few posts, but have you *really* considered using a database?
I mean, mySQL isn't your only option (though undoubtedly the best).
phpinfo() can tell you in pretty short order of you have sqlite running on your sever, and once you get the hang of it, it's pretty straight forward to use.
Just a thought.
Posted: Tue Oct 16, 2007 6:30 am
by Sindarin
Maybe I'll go with database if it doesn't require too much time to learn.
Posted: Tue Oct 16, 2007 7:47 am
by Stryks
Well ... to really get good at it takes a while .. .especially on the design side, but for basic data selects, inserts, updates and deletes you can get away with next to no knowledge at all. Especially when you have access to the wealth of information and expertise this forum provides.
The basics of SQL are surprisingly simple, and as for handling the data you pull back from the database, if you aren't scared off by arrays, you should have no major problems.
If it turns out that mySQL isn't available, create a blank php containing
and give it a run.
SQLite is an option if that page has sections for PDO and pdo_sqlite, and / or SQLite (preferably all). It's a little non-standard, but I've seen it around on a lot of host servers. You might be lucky.
The first step in going further with this would be to find out what you *can* do. Then you can decide what is going to be the best option.
Or you could persist with the file manipulation. Personally though, I think the learning curve is steeper with that route.