loa92 Posted March 21, 2003 Share Posted March 21, 2003 I know that "include" would insert an entire page, but is there any way to take a small portion of that page, something that has already defined as <something> Blah Blah, Some odd text. <something> Not sure if I'm makeing sence, but that's why i'm asking. :blush: Thanks! Link to comment Share on other sites More sharing options...
0 Quboid Posted March 21, 2003 Share Posted March 21, 2003 You could have the included file being a list of functions, with each function printing out a small portion. At the top of your script, require_once("page.inc.php"); and then when you want to print a section, call the relevent function. This isn't a great way of doing it, but it'll work. Only problem I can think of could be with variables' being global or not. Another solution would be to have several includes and use a long if statement or a switch to choose the right one. A third solution and possibly the best would be to set a variable before calling the include. Then in the include, have an if statement or switch or whatever fits which checks the variable and only prints what's needed. Link to comment Share on other sites More sharing options...
0 Nibbles Posted March 21, 2003 Share Posted March 21, 2003 Have you ever used "PHP" before???? Link to comment Share on other sites More sharing options...
0 epton Posted March 22, 2003 Share Posted March 22, 2003 you'll have to use fopen(), not include(). Link to comment Share on other sites More sharing options...
0 loa92 Posted March 22, 2003 Author Share Posted March 22, 2003 Well I tried a little bit of everything but none seemed to work so let me rephrase. Basically all I want to do is take a chunk of text from one page and include it in another. The text is encapsulated in <body_txt> </body_txt> I don't need the entire page, just the text from this area, as the text changes every so often, but the name body_txt doesn't. I don?t have much PHP coding under my belt, thus the tread, but I figured PHP would be ideal for this job, but maybe not. Any other suggestions would be appreciated! Link to comment Share on other sites More sharing options...
0 linked Posted March 22, 2003 Share Posted March 22, 2003 I know there's a way to do that, but no clue what it is. So my best guess is this- fwrite() the body text to bodytext.php have both pages <? include(bodytext.php) ?> Link to comment Share on other sites More sharing options...
0 loa92 Posted March 22, 2003 Author Share Posted March 22, 2003 I like that suggestion, but my next question would be: how do I get the "body txt" into a string. It prob has to do with pointers, but I can't seem to figure it out. Thanks again! Link to comment Share on other sites More sharing options...
0 lonedawg Posted March 22, 2003 Share Posted March 22, 2003 you could use regular expressions (ereg, preg_match) ie (where <larf> is a unique section of text before the part you want to match, and </larf> is a unique section after the part you want to match) $file = fopen("file.html", "r+"); $contents = fread($file, filesize("file.html")); preg_match("/<larf>(.*)</larf>/", $contents, $matches); echo($matches[0]); i'm not sure if that's exactly syntaxically correct but it's a step in the right direction the only problem with this method is having to load the entire file into ram first Link to comment Share on other sites More sharing options...
Question
loa92
I know that "include" would insert an entire page, but is there any way to take a small portion of that page, something that has already defined as
<something>
Blah Blah, Some odd text.
<something>
Not sure if I'm makeing sence, but that's why i'm asking. :blush: Thanks!
Link to comment
Share on other sites
7 answers to this question
Recommended Posts