0

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.

Jesse Atkinson
  • 10,586
  • 13
  • 42
  • 45
  • http://stackoverflow.com/questions/4348912/get-title-of-website-via-link – Gundars Mēness Aug 11 '12 at 22:25
  • I really would not use `http://$_SERVER[HTTP_HOST]` as it is prone to many bugs if not done right: `'Hello, $first_name'` Say for some reason, you meant `'Hello, '.$first.'_name'`. PHP, will read `'Hello, '.$first_name` – Cole Tobin Aug 11 '12 at 22:29
  • @ColeJohnson: actually, that's one of the things where single quotes and double quotes differ. If you use `'Hello, $first_name'` you get exactly that. However, if you use `"Hello, $first_name"` the result will be the same as `'Hello, '.$first_name` – Arjan Aug 11 '12 at 22:34
  • @Arjan you're right, I meant to use double quotes. Oh how I hate PHP. – Cole Tobin Aug 11 '12 at 22:40
  • Gundars Meness, that question doesn't help because I'll need to enter the URL manually and I don't want to do that. My method or approach might be wrong. You can see what I am attempting to do. I don't know how else to do it. – Jesse Atkinson Aug 11 '12 at 22:41

1 Answers1

0

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/

mkey
  • 212
  • 1
  • 5