homepage Welcome to WebmasterWorld Guest from 54.196.159.11
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?
Catnip




msg:1294237
 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.

 

lorax




msg:1294238
 6:23 pm on Nov 14, 2002 (gmt 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>

Catnip




msg:1294239
 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,

Ryan

jatar_k




msg:1294240
 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.

dingman




msg:1294241
 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.

lorax




msg:1294242
 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.

mack




msg:1294243
 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.

dingman




msg:1294244
 7:57 pm on Nov 14, 2002 (gmt 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>

andreasfriedrich




msg:1294245
 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.

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




msg:1294246
 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) { 
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




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

Andreas,

How do you come up with this stuff? :)

andreasfriedrich




msg:1294248
 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.

Andreas

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