I currently am using two PHP scripts; 1 to post content to a file and 1 to get content from the file from between two tags.
Post Content Script:
$content = $_POST["maintenancetext"];
$strNewContents = "$content";
$fileRefID = fopen("../../../maintenance.php", "w");
fwrite($fileRefID, $strNewContents);
fclose($fileRefID);
Get Content from between two tags script:
$start = '<p>';
$end = '</p>';
$string = file_get_contents("../../../maintenance.php");
$output = strstr( substr( $string, strpos( $string, $start) + strlen($start)), $end, true);
echo htmlentities($output, ENT_QUOTES);
I am currently posting from a text area to the file however I need this content to be changed between two tags only.
How can I achieve this? Thanks.
Assuming post content script is working, now to get content between two tags:
$string = file_get_contents("../../../maintenance.php");
$matches = array();
$pattern = "'<p>(.*?)</p>'si";
preg_match($pattern, $string, $matches);
$output = $matches[1];
echo $output;
To replace content:
$newstring = "i am new string";
$newouput = str_replace($output, $newstring, $output);
echo $newoutput;