Forum Moderators: coopster
What I thought of doing was to use something like strpos of two different tags;
ob_start();
require_once("index.php");
$buffer = ob_get_contents();
ob_end_clean();$pos1 = strpos($buffer, "//extra php here");
$pos2 = strpos($buffer, "//end extra php");
However this does not seem to work - maybe it is because there are spaces in the string - but how can I get the positions of these two markers in the $buffer - or is there a better way of doing this?
I would also need something to get rid of everything at the beginning up until the marker, and everything after the 2nd marker.
The only thing I have thought of, is to perhaps create another file to contine the extra PHP code in - but why increase used disk space, whilst also possibly letting the users see source code...
... if anyone could perhaps suggest a better idea, or a solution - I would be most greatful!
Thanks!
// Find your starting point delimiter in the original text
$array1 = explode(delimiter,$text);
// Find the ending point delimiter in the array
$array2 = explode(delimiter,$array1[1]);
$array2[0] should have the value you are searching for.
JAG
<?
$buffer = implode('', file('index.php'));
$array1 = explode("//extra php start",$buffer);
$array2 = explode("//extra php end",$array1[1]);
$contents = $array2[0];
echo "<textarea cols=50 rows=10>$contents</textarea>";
?>
I'm sure i've tried to use file() beofre but somehow it did not work, I also check in the PHP manual and it suggested the first line... and it works, and now I happy :)
Thanks again!
Edit: Just one more thing - on the same page, is there a way to extract the contents of a varible (outside of these tags) without including the page? For example;
//extra php start
$stuff = "bla bla bla";
//extra php end
$title = "Interesting page";
If I want to include the $title varible into an input field to be edited, what is the best way to go about extracting it? I know it can be done by including the page, or using the ob_start() thing - but is there a better way?
Thanks!
$buffer = implode('', file('index.php'));
This is exactly the same as:
$buffer = [url=http://us3.php.net/manual/en/function.file-get-contents.php]file_get_contents[/url]('index.php');
As to the other thing, what I do for things like that is declare a small include file with various variable settings, and declare them as global. I then include this small file in the various files that use the variables, and I don't have to worry about including the big kahuna.