Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How can i create new page on my website using PHP? I need PHP-code, which can create a new page. For example, i've got index.php and i need to create index2.php w/ PHP. Thanks.
Like above answer you can use fopen() and fwrite() to build a new .php file, or you could try using file_put_contents() which would also generate a new file if it doesn't exist.
file_put_contents($filename, $content);
Example
$filename = "index2.php";
$content = "<h1>hello world</h1>";
file_put_contents($filename, $content);
Use fopen() to create a file, and fwrite to edit it, more info here :
http://www.w3schools.com/php/php_file_create.asp
Open Notepad (if your do not have any other softwares like Notepad++ or Dreamweaver for editing PHP code), write your code there, Save the text file with .php extension in the same directory where your index.php file is located.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am trying to call an HTML file in a php file but cant really get any right answer.
I have tried:
<?php require/include('filename');>
as well as
readfile('filename');
Doesn't work. How do I do that?
If you are trying to get the html content inside a php file, you can change your .html file extension to .php and use include() or require().
Example, if you have a file named headings.html, rename it to headings.php and then use:
require('headings.php');
While require() will produce a fatal error if the file is not found, include() will only produce a warning.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm using a plugin that updates alsmost evert week, and when that happens it overrides every work that I've done. I welcome the updates but not when it overrides my inputs. I'm trying to keep my inputs in seperate file and have a code in place that will find the pluging file and include my inputs as a file. That way nothing will break, my inputs and the updates will both be intact. my code looks like below.
$useThis = 'search-processor.php';
$putHere = "um-actions-members.php";
file_put_contents($useThis, $putHere, FILE_APPEND | LOCK_EX);
This way you will not parse the PHP commands, you only include what is inside the php file
$useThis = "search-processor.php";
$putHere = "um-actions-members.php";
// get the content of $putHere
$fileContent = file_get_contents($putHere);
file_put_contents($useThis, $fileContent, FILE_APPEND);
To parse the PHP commands you need to go inside the $useThis and use the include command, like
include("um-actions-members.php");
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to extract the source code from a website and want to save it in a text file on wamp server. So kindly help me.
It is not very complicated, you can get the content of a file by calling file_get_contents() this includes files on the web.
Then you just need to write the content to a file and presto you have extracted the .html source and saved it in a text file by using php.
<?php
// Open a webpage
$homepage = file_get_contents('http://www.example.com/');
// echo the homepage to see the content.
echo $homepage;
// Set the filename
$file = 'hp.txt';
// Write the contents back to the file
file_put_contents($file, $homepage);
?>
Hope this is what you need.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Hello, I Was wondering if there was a way to use php to call on a css file and insert data into it. The purpose would be to to allow a user to easily modify a css file instead of having to go into the file manually. It would be a field called Width: with a text area for them to enter it in.
Sure. You can easily read a file with file_get_contents and then write it back to the file with file_put_contents.
// load the css file into a string
$css = file_get_contents("my.css");
// make changes, e.g....
$css = str_replace("width: 10px;", "width: 20px;", css);
// save those changes
file_put_contents("my.css", $css);
Create an script to "generate special css" using functions like fwrite() that will create an special css for each user and then load it if user is logged to overwrite the original css
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I use this in htm file to include another htm file
<?php include("media/android.htm"); ?>
Is this safe?
Both of them are simple htm file with text and pictures.
Yes, it's completely safe. That's how PHP works.
But, keep in mind that's a php file, not html.
use jquery to load a file
$("#div1").load("media/android.htm");
Try this
include file without php