Hi,
I have to post news articles on a website every couple of days. I use a html page as a template and simply cut and paste the textual paragraphs into the html and then save the page as a different name.
I'd ideally like to use php to automate this process. I have a test script working, I provide the user with an input screen and via a form I post this data (such as article title, sub heading, paragraph1, paragrap2 etc,.) to the template page.
Now on the template page I can echo the relevant variables to the screen so that on screen the process works, but my question is........ will it be possible to save the template file as say "newsarticle_2" with the form data variables as hardcoded text.
Therefore each time an article is submitted a new page is created and saved.
Any ideas, if so how do I do this.
Thanks,
Rob.
Content management system
Moderator: General Moderators
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
Ya, you could do that. If you're echoing the template page, you can capture that and put it in a string. You can then write that string to a file.
~BDKR has the best idea though. It's best to store it in a database. That way its way easier to edit the page after the fact. Also, if the template changes, it's much easier to put database content into a template, rather than having to pull the content out of an html file and put it in a new one.
Code: Select all
ob_start();
echo $contents_of_template;
$complete_page = ob_get_contents();
ob_end_clean();
$fh = fopen('testpage.html','w');
fwrite($fh,$complete_page);
fclose($fh);Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
In most cases, database systems will have URLS like: http://www.domain.ca/page.php?id=sunday_blog
You can use .htaccess (providing you're using Apache) files to create an imaginary URL like http://www.domain.ca/sunday_blog which will show the above URL. There are lots of tutorials on how to do this.
You can use .htaccess (providing you're using Apache) files to create an imaginary URL like http://www.domain.ca/sunday_blog which will show the above URL. There are lots of tutorials on how to do this.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.