October 29, 201015 yr Hi, i am looking to create a PHP page that would have a submission form that when submitted creates a new page based on the contents of the page. For example, there could be a YouTube link field which would then display that video on the page generated to blah.com/videos/randomurl.html. I'm unable to find anything on Google as i keep getting results for creating PHP pages in the sense of a starter PHP tutorial. Thanks in advance.
October 29, 201015 yr Hi, i am looking to create a PHP page that would have a submission form that when submitted creates a new page based on the contents of the page. For example, there could be a YouTube link field which would then display that video on the page generated to blah.com/videos/randomurl.html. I'm unable to find anything on Google as i keep getting results for creating PHP pages in the sense of a starter PHP tutorial. Thanks in advance. do you mean redirecting to another page after form submition ? or creating a totaly new page? im sure it can be done as you can create new folders in your directory via php script. would you be able to give a litle more detail? or tell us exactly what you want to do with you page
October 30, 201015 yr Author Well, i want to create a brand new HTML file from a preset template (things like title, main text etc would be entered into the form). I know that there are ways using MySQL and GET, but i'd rather have an entirely new page. Hope this helps you understand.
October 30, 201015 yr You can use file_put_contents $html = '<html><head><title>This is the title</title></head><body><p>Hello World.</p></body></html>'; file_put_contents('my-file.html', $html); Or generate the document using DOM <?php $doc = new DOMDocument('1.0'); $root = $doc->createElement('html'); $root = $doc->appendChild($root); $head = $doc->createElement('head'); $head = $root->appendChild($head); $title = $doc->createElement('title'); $title = $head->appendChild($title); $text = $doc->createTextNode('This is the title'); $text = $title->appendChild($text); $body = $doc->createElement('body'); $body = $root->appendChild($body); $paragraph = $doc->createElement('p'); $paragraph = $body->appendChild($paragraph); $text = $doc->createTextNode('Hello World.'); $text = $paragraph->appendChild($text); $doc->saveHTML('my-file.html');
October 30, 201015 yr First create the page and load it into a php variable - e.g <?php $html_page = <<<YOURHTML <html> <head><title>Your title</title></head> <body>Your body contents here... <?php echo "You can still put some php codes... ?> </body> </html> YOURHTML; ?> Note: There are other ways of doing this. Then put a link that calls your php page. Your php page could look like this - <?php echo $html_page; ?> I assume you already know how to pass info across pages.
October 30, 201015 yr Author Thanks a lot for the replies. I now have this sorted I really appreciate the help
Create an account or sign in to comment