So, I'm a PHP newbie who has been trying to do a PHP program that will edit some other PHP program by adding some more info.
How I want this to work:
edit.php
with an argument add=(text)
, (text) is some random text you may want to add.(text)
gets added to raw.php
by changing 2nd line from echo "(already existing text)"
to echo "(already existing text) (text)"
Can somebody help me? I can't figure this out. Any help would be appreciated!
I'd like to suggest you this aternative way: Add a new file for the text content, a JSON file would be perfect, but i don't want to make it more complicated, we will stick with a txt for now. It's not good to edit the php source code with another php script, it is often done by malicious script.
So we have:
//This is raw.php
/*This is the new content retrived with GET*/
$my_new_content = $_GET["add"];
/*Update txt file with the new content,
the new text will be append, I add an extra space in the front.*/
file_put_contents("mycontent.txt", " " . $my_new_content, FILE_APPEND);
/* Read the actual text from the txt file */
$my_brand_new_content = file_get_contents("mycontent.txt");
echo $my_brand_new_content;