Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am attempting to dynamically grab a page's title and URL and echo into HTML. Here's what I have:

<ul>
    <li><a href="mailto:?Subject=<?php echo $page_title?>&body=<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>" class="email" title="Email">Email</a>
    </li>
</ul>

The URL successfully echos, but I'm not sure if this is the correct way? And I can not figure out how to print the page's title via <?php echo $page_title?>?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
245 views
Welcome To Ask or Share your Answers For Others

1 Answer

There is no global PHP variable which corresponds to the page <title>. Unless you earlier used the $page_title variable to specify the <title>...

<?php $page_title = "My Page Title"; ?>
<title><?php echo $page_title ?></title>

...<?php echo $page_title?> wont' do anything special.

If you did use the $page_title variable in this way, you might need to encode the data. It should be both URI encoded and HTML encoded - in that order.

<a href="mailto:?Subject=<?php echo htmlentities(urlencode($page_title)); ?>" class="email" title="Email">Email</a>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...