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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.