how to write a php code such that a link specified must directly display the contents of the link in the browser..??

thanku,

Recommended Answers

All 5 Replies

how to write a php code such that a link specified must directly display the contents of the link in the browser..??

thanku,

The thing to remember is that browsers never interact directly with PHP code. PHP is server-side script. It is run on the server, which then sends html/css/javascript to the browser.

Therefore, we're dealing with an HTML issue, not a PHP issue. If your question means that you don't want the link to open a new window, you could leave off the "target" attribute in the anchor link (target="_blank" is the one that opens a new browser window).

<a href="/openthispage.php">Open this page</a>

(Above is labeled "PHP syntax" but it is really HTML syntax)
To do this within PHP tags, use the "echo" command -
<?php
$link = "<a href='/openthispage.php'>Open this page</a>";
echo $link;
?>

So if I understand correctly, you want to grab the contents of a web page, and display it in your browser?
The basic method of doing that is like this:

<?php
    print(file_get_contents("http://example.com/"));
?>

The only problem with this is that it grabs the HTML exactly as it appears on the page, so any relative links will be broken. If the page uses relative linking, then you'd have to write a regular expression and use preg_replace().

What is the easy and fast way to learn PHP. and what are the basic requirements for it. I know only HTML. Plz suggest me. Thanks.

Member Avatar for diafol

Buy a good book and go through it at your own pace. Online tutorials are all well and good, but I find nothing beats a decent book when starting out. See O'Reilly/Sitepoint/Wrox.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.