开发者

I want to use part of a pages URL as the page title using PHP

I have hundreds of pages, each with a unique url. All the 开发者_如何学运维pages are the same with the exception of the url which is also the name of the page. How can i get the page to read the url and place the name (parsing the http://www. and the .tld? It needs to be both the Title of the page as well as be shown else where on the page. Can this be done in PHP?


If you use this code it will only grab the domain name without the http://www. You can then use a substring query to remove the .tld.

<?php
# Using HTTP_HOST

$domain = $_SERVER['HTTP_HOST'];
$domain = substr($domain, 0, -4);

echo "<title>" . $domain . "</title>";
?>

If you place this code in between the tags , then you will get a dynamic title based on the URL.


Add the following code to a page:

<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
?>

You can now get the current page URL using the line:

<?php
  echo curPageURL();
?>

check PHP: How to Get the Current Page URL

I didn't understand the rest of your question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜