Welcome to WebmasterWorld Guest from 54.196.244.186

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Displaying the contents of a URL/PHP

How do I do it?

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

Junior Member

10+ Year Member

joined:Nov 1, 2002
posts:86
votes: 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)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7575
votes: 0


Catnip,
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)

Junior Member

10+ Year Member

joined:Nov 1, 2002
posts:86
votes: 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,

Ryan

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

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 12, 2002
posts:885
votes: 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)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7575
votes: 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)

Moderator from GB 

WebmasterWorld Administrator mack is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:June 15, 2001
posts:7557
votes: 3


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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 12, 2002
posts:885
votes: 0


Mack-
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.

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

Do we even see this?

</body>
</html>

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 0


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

ob_start(); 
require('directory/page.php');
$included_code = preg_replace(array(
"'(<[!\?][^>]+)?\s*<html\s*>.*?<body[^>]*>'",
"'</body\s*>\s*</html\s*>'"), '', ob_get_contents());
ob_end_clean();
echo $included_code;

Andreas

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

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 0


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

function crazy_callback($buf) { 
return(preg_replace(array(
"'(<[!\?][^>]+)?\s*<html\s*>.*?<body[^>]*>'",
"'</body\s*>\s*</html\s*>'"), '', $buf));
}
#
ob_start('crazy_callback');
require('directory/page.php');
ob_end_flush();

Andreas

<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)

Full Member

10+ Year Member

joined:Apr 4, 2002
posts:236
votes: 0


Andreas,

How do you come up with this stuff? :)

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 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.

Andreas