0

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

thanku,

5
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by diafol
0

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;
?>

Edited by compusolver: Explaining that labeled PHP syntax is actually HTML

0

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

0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.