简体   繁体   中英

How to get contents of h1 with PHP for use in Twitter data-text param

Here is the contents of my twitter.php include:

<?php
$tags = get_meta_tags();
echo $tags;
$dynamic_tweet_text="Episode Title by @OurCityOurStory: http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
?>

<a href="https://twitter.com/share" class="twitter-share-button" rel="canonical" data-text="<?php print $dynamic_tweet_text ?>">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

The part that reads "Episode Title" of $dynamic_tweet_text needs to be dynamic. I need to grab it from the h1#title .

How do I do this? It has to be done server-side due to the way Twitter's JS works and I'm not great with PHP.

If you are familiar with jquery you can use library which allows you to get content by selectors, ids, elements, etc. - just like in jquery. Check this out http://simplehtmldom.sourceforge.net/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM