Let's say I have a PHP file (index.php) that displays another PHP file (info.php) within a textarea using file_get_contents() function. Is it possible to define some sort of tags in info.php so that index.php will only get the content between those tags?

Is there a way to get only the content between display tags or something like that?

Pullo
—
2012-11-20T09:07:48Z —
#2

Hi,

AFAIK the function file_get_contents() loads all the contents of a file into a string.If you know the exact position of the content you want, you can use the offset and maxlength parameters to read only a section.For example:

Or, if it's not too much of a performance hit, maybe you could get the whole file as a string, then simply remove everything before and after the markers using substr().

frank1
—
2012-11-20T13:53:48Z —
#3

yup you can use file_get_contents which returns values as string then use regular expression to extract the part identifying the pattern....

nayen
—
2012-11-20T14:01:03Z —
#4

Pullo said:

Hi,

AFAIK the function file_get_contents() loads all the contents of a file into a string.If you know the exact position of the content you want, you can use the offset and maxlength parameters to read only a section.For example:

Or, if it's not too much of a performance hit, maybe you could get the whole file as a string, then simply remove everything before and after the markers using substr().

I will use that on different files so there is no exact position. I will try and see what I can do with subsrt().

frank1 said:

yup you can use file_get_contents which returns values as string then use regular expression to extract the part identifying the pattern....

Your suggestion seems to be the solution, could you please elaborate it a little, maybe a very simple example?

frank1
—
2012-11-20T14:11:42Z —
#5

ok using this approach,if the content of the page you are accessing is dynamic(which is most of the time)$section = file_get_contents('./yourFile.php', NULL, NULL, 20, 14);will return different part every time the page is changed.

file_get_contents will return the html source(from top header,meta to /html) code of the page(file) you access in string format.

The content may be different but structure of the file may be same

for eg,if you want to get values between

<table><tr><td>value--can be anything</td>or <table class='name'>...

so you can use those kind of information to write an regular expression and get the value which will be much generic...I mean run regular expression over string obtained from file_get_contents and get the value you want.