Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Generate a page through PHP

Featured Replies

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.

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

  • 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.

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');

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.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.