如何将php中的变量插入p标签(html)?

时间:2017-05-10 16:14:21

标签: javascript php jquery html twitter

我想让我的推特追随者数量显示在我的网站上。我已经设置了twitter API以接收跟随者计数,并且已经使用echo进行了测试,并且运行正常。

问题是我无法解决如何将该值传递给html。

这是获取推特计数的代码:

<?php 

/* 
 * Requires the "Twitter API" wrapper by James Mallison 
 * to be found at https://github.com/J7mbo/twitter-api-php
 *
 * The way how to get a follower count was posted by Amal Murali
 * on http://stackoverflow.com/questions/17409227/follower-count-number-in-twitter
 */

require_once('twitterapi/TwitterAPIExchange.php');              // adjust server path accordingly

// GET YOUR TOKENS AND KEYS at https://dev.twitter.com/apps/
$settings = array(
'oauth_access_token' => "SECRET",               // enter your data here
'oauth_access_token_secret' => "SECRET",        // enter your data here
'consumer_key' => "SECRET",                 // enter your data here
'consumer_secret' => "SECRET"               // enter your data here
);

$ta_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?screen_name=SECRET';                  // enter your twitter name without the "@" here
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$follow_count=$twitter->setGetfield($getfield)
->buildOauth($ta_url, $requestMethod)
->performRequest();
$data = json_decode($follow_count, true);
$followers_count = $data[0]['user']['followers_count'];

?>

这是将$ followers_count变量传递给html的代码。

它是一个带有id&#34; twit-follow-count&#34;的span标签。

<script type="text/javascript">

$( document ).ready(function() {
    $('#twit-follow-count').html($followers_count);
});

</script>

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:3)

$f1=(import-csv 'C:\Desktop\ListA.csv' -header FirstName, LastName, Birthdate, PersonID, Address, PhoneNumber)[1..999]
$f2=(import-csv 'C:\Desktop\ListB.csv' -header PersonID, Address, PhoneNumber)[1..999]
$f1|
   %{
      $PersonID=$_.PersonID
      $m=$f2|?{$_.PersonID -eq $PersonID}
      $_. Address=$m.Address
      $_. PhoneNumber=$m.PhoneNumber
    }
$f1 | ConvertTo-Csv -NoTypeInformation | select -Skip 1 |  % {$_.Replace('"','')} | Out-File 'C:\Desktop\ListAFinal.csv'