Welcome to WebmasterWorld Guest from 54.167.5.15

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Displaying the contents of a URL/PHP

How do I do it?

     

Catnip

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

10+ Year Member



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.

lorax

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

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



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>

Catnip

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

10+ Year Member



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

jatar_k

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

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



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.

dingman

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

WebmasterWorld Senior Member 10+ Year Member



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.

lorax

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

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



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.

mack

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

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



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.

dingman

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

WebmasterWorld Senior Member 10+ Year Member



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>

andreasfriedrich

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

WebmasterWorld Senior Member 10+ Year Member



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]

andreasfriedrich

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

WebmasterWorld Senior Member 10+ Year Member



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]

dhdweb

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

10+ Year Member



Andreas,

How do you come up with this stuff? :)

andreasfriedrich

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

WebmasterWorld Senior Member 10+ Year Member



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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month