简体   繁体   English

如何使用PHP获取h1的内容以在Twitter数据文本参数中使用

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

Here is the contents of my twitter.php include: 这是我的twitter.php的内容,包括:

<?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. 读取$dynamic_tweet_text “情节标题”的部分必须是动态的。 I need to grab it from the h1#title . 我需要从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. 由于Twitter的JS的工作方式,它必须在服务器端完成,而我对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. 如果您熟悉jquery,则可以使用库,该库允许您通过选择器,id,元素等获取内容-就像在jquery中一样。 Check this out http://simplehtmldom.sourceforge.net/ 看看这个http://simplehtmldom.sourceforge.net/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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