Jump to content

Fwrite Data As Input


pizzaguy
 Share

Recommended Posts

Is there anyway to have a PHP file "pretend" to be written to, but instead process what was supposed to be written to is as input? Basically, if I use fwrite to write "hello world" to "test.php", I want "test.php" to take "hello world" as variable input, instead of actually having "hello world" written into the file; is that possible?

Link to comment
Share on other sites

You can just directly write PHP code to a file. But what you're asking doesn't make much sense, there are likely many more efficient ways to do whatever you're trying to do. Can you explain why you want to write in a file expecting it to be stored in a variable?

Link to comment
Share on other sites

its basically laziness. I have a plugin for my wordpress blog. It takes all the posts and writes them to a sitemap.xml file (the file can be user specified). I wanted change it to have the data written to a database, and then have a php file write it when called. I figured the easiest way would be to do what I am saying above. Change the setting to have it write to sitemap.php, but instead of writing to the file, sitemap.php would take the information and write it to a database...

Link to comment
Share on other sites

It would be easiest to modify Wordpress to write to a database instead of a file, and change sitemap.php to read from the database. You would just need to find and change the code that creates the sitemap. You can't "intercept" fwrite and make it do something else like that. You would need to change the code for the fwrite function in order to do that. That's beside the issue though - when they use fopen it immediately deletes the contents of the file.

Edited by justsomeguy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...