Jump to content

Needed: code to return path of web page, including title


tuco

Recommended Posts

Hello,

Can someone help me with what I *think* is a simple bit of code?

On an arbitrary web page, I would like the code to return the web path to that page and including the title of that page.

The purpose is to provide folks who might want to link to the page the actual code they need to make the link by cutting and pasting the link into their own site.

Something like this:

[code]<a href="http://www.phpfreaks.com/example.php">Page Title</a>[/code]
this'll give you the url of where you are...
[code]
<?
function get_url(){
if(!empty($_SERVER[QUERY_STRING])) return 'http://'.$_SERVER[SERVER_NAME].$_SERVER[PHP_SELF].'?'.$_SERVER[QUERY_STRING];
else return 'http://'.$_SERVER[SERVER_NAME].$_SERVER[PHP_SELF];
}
?>
[/code]

and prolly the easiest way of getting the title, would be setting it as a var first...
[code]
$title="title";
echo "<title>$title</title>";
echo "<a href=\"get_url()\">$title</a>";
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.