homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Displaying the contents of a URL/PHP
How do I do it?

 6:18 pm on Nov 14, 2002 (gmt 0)

How can I display the contents of a url on a page. Without the obvious cut and paste. I want to display it this way so when then information changes on my main page it will also update on the other.. so they are linked. Everything is done with PHP, and the person that does it is away.



 6:23 pm on Nov 14, 2002 (gmt 0)

Are you talking about the URI of the person visiting the page or the URL of the actual page they're viewing?
<edited>I just reread your post. This will most likely get moved to the Scripting forum because that is what you need to do. It's not easy if you're not used to working with script languages. Do you want to try it?</edited>


 6:27 pm on Nov 14, 2002 (gmt 0)

Yeah I have some idea about php and I have done things like it before. I was thinking someone already may have an example and could help me.

I want to do the following here is my attempt at an example

www.beer.com/molson/canadian/marketing/country/state/mode/1/ <---info I want.

www.beer.com/brands/marketing/bubba/ <--- Where I want to include the information from the link above.

So that every time my bubba page loads it pulls the information from mode/1/

Please Help,



 6:53 pm on Nov 14, 2002 (gmt 0)

is the site driven by a db? If so you would just have to use the same content from the db as the other page.

It would help if you could give a few more specifics about how the site functions, back end etc.


 7:05 pm on Nov 14, 2002 (gmt 0)

If you're not using a DB, I'd probably make both pages include() the same file with the content you want them to share. Saves you reading in the source file, parsing out the headers and stuff you don't want, etc. Adam's right, though. It would be easier to help you if we knew more about your set-up.


 7:16 pm on Nov 14, 2002 (gmt 0)

Like jatar_k and dingman said, we need to know if the source page is created by a data from a database or from an external file. Providing you're sure it's generated by PHP.


 7:23 pm on Nov 14, 2002 (gmt 0)

If the page you are making is written in php and the page you want to insert is written in php would this not work?

require ("directory/page.php") ;

where "directory" points to the directory holding/the/php/page and "page.php" is the name of the page you wish to insert.


 7:57 pm on Nov 14, 2002 (gmt 0)

If the page he is trying to includde produces a valid HTML document, then including it wholesale in another page will produce an invalid page.

<whatever else>
Valid so far...
<!-- next line is 'require("directory/includee.php");' -->
<html> <!-- see the problem? -->
Content we were after with the include

Do we even see this?



 8:36 pm on Nov 14, 2002 (gmt 0)

You probably donīt want to do it this way, but this should work and solve the problem indicated by dingman.

$included_code = preg_replace(array(
"'</body\s*>\s*</html\s*>'"), '', ob_get_contents());
echo $included_code;


[edited by: andreasfriedrich at 8:44 pm (utc) on Nov. 14, 2002]


 8:42 pm on Nov 14, 2002 (gmt 0)

This does the same crazy stuff as the code in my previous post but does it more elegantly. ;)

function crazy_callback($buf) { 
"'</body\s*>\s*</html\s*>'"), '', $buf));


<edited>While the code is more elegant my use of an adjective instead of an adverb in my intoductory sentence was not. I hope I got it right this time.

BTW feel free to point out grammatical errors in my posts if you feel like it and have the time. Iīm always eager to improve my English.</edited>

[edited by: andreasfriedrich at 11:15 pm (utc) on Nov. 14, 2002]


 10:56 pm on Nov 14, 2002 (gmt 0)


How do you come up with this stuff? :)


 11:23 pm on Nov 14, 2002 (gmt 0)

I made that up on the fly. It was a nice stupid little problem (no offense intended) and something that one should probably never do if one can help it. So hacking together a solution was a must, wasnīt it?

And I learned something new: Output buffers are stackable. That is why this code will work even if output buffering is already used.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved