Click to See Complete Forum and Search --> : Get part of another file


alxla
01-25-2007, 01:33 PM
I want to get a part of the html from another file and read it into an array.
But how?

I have heard of that you can do it between comment tags, but i cant find anything on google :S

NightShift58
01-25-2007, 03:40 PM
First, to get the HTML file, you'll use file_get_contents() (http://cr.php.net/manual/en/function.file-get-contents.php). With that file, you'll filter in/out whatever segments you need, as you define it. When done, you can explode() (http://cr.php.net/manual/en/function.explode.php) the remaining contents to an array.

If you use regular expressions, something like: $bokeh = preg_magic() [NB: not a real function... yet...], then your content may already be in array form. You would then have to convert the results into whatever format you need, either looping through the resulting array or using an existing array function (http://cr.php.net/manual/en/ref.array.php).

alxla
01-25-2007, 05:14 PM
Okey, how do i filter out my segments then?
And why should i explode it into an array?
I'm not so use with php, that's why i'm ascing this stupid question. But you gotta start somewhere ;)

NightShift58
01-25-2007, 05:29 PM
There's no quick answer to that. It depends on the data you want to parse/filter. If you provide examples, there are a couple of regular expression magicians who routinely look in...

MrCoder
01-26-2007, 05:40 AM
*Pulls a rabit out of a hat*

alxla
01-26-2007, 07:11 AM
Ok i can write a small "exmple":

File with info.;info.html:
<HTML>
<body>
<!-- hello -->
Hello world
<!-- end hello -->
<!-- today-->
Today is a blue day
<!-- end today--><!-- yesterday-->
Yesterday was a green day
<!-- end yesterday--><!-- tommorrow-->
Tommorrow is a ornage day
<!-- end tomorow-->
</body>
</HTML>

And i want a file that fetches part of the file, and the output will be like:
<HTML>
<body>

Today is a blue day

Tommorrow is a ornage day

</body>
</HTML>

And if you edit the first file the second will be updated automatic.

MrCoder
01-26-2007, 10:13 AM
Sounds very much like Dreamweaver templates?
Im pretty sure there tutorials on the net for striping dreamweaver templates (thats very much like your example).

I just found one..
http://www.cmarshall.net/MySoftware/DreamweaverTemplate/index.php

Download and examine the code, think its what your after?

alxla
01-26-2007, 12:28 PM
No it's not like that. I already have built up my site with ordinairy templatefiles.
What i want is to take out some information from a plain html file and put it in a variable in string format.