Jump to content
Fórum Script Brasil
  • 0

Formatar número


Question

Olá a todos! Estou usando essa função pra pegar o número de seguidores no Twitter :

Olá Pessoal!
Queria saber como formatar o número dentro dessa função:


function getTwitterFollowers($screenName = ‘wpbeginner’)
{
// some variables
$consumerKey = ‘YOUR_CONSUMER_KEY’;
$consumerSecret = ‘YOUR_CONSUMER_SECRET’;
$token = get_option(‘cfTwitterToken’);

// get follower count from cache
$numberOfFollowers = get_transient(‘cfTwitterFollowers’);

// cache version does not exist or expired
if (false === $numberOfFollowers) {
// getting new auth bearer only if we don’t have one
if(!$token) {
// preparing credentials
$credentials = $consumerKey . ‘:’ . $consumerSecret;
$toSend = base64_encode($credentials);

// http post arguments
$args = array(
‘method’ => ‘POST’,
‘httpversion’ => ‘1.1’,
‘blocking’ => true,
‘headers’ => array(
‘Authorization’ => ‘Basic ‘ . $toSend,
‘Content-Type’ => ‘application/x-www-form-urlencoded;charset=UTF-8’
),
‘body’ => array( ‘grant_type’ => ‘client_credentials’ )
);

add_filter(‘https_ssl_verify’, ‘__return_false’);
$response = wp_remote_post(‘https://api.twitter.com/oauth2/token’, $args);

$keys = json_decode(wp_remote_retrieve_body($response));

if($keys) {
// saving token to wp_options table
update_option(‘cfTwitterToken’, $keys->access_token);
$token = $keys->access_token;
}
}
// we have bearer token wether we obtained it from API or from options
$args = array(
‘httpversion’ => ‘1.1’,
‘blocking’ => true,
‘headers’ => array(
‘Authorization’ => “Bearer $token”
)
);

add_filter(‘https_ssl_verify’, ‘__return_false’);
$api_url = “https://api.twitter.com/1.1/users/show.json?screen_name=$screenName”;
$response = wp_remote_get($api_url, $args);

if (!is_wp_error($response)) {
$followers = json_decode(wp_remote_retrieve_body($response));
$numberOfFollowers = $followers->followers_count;
} else {
// get old value and break
$numberOfFollowers = get_option(‘cfNumberOfFollowers’);
// uncomment below to debug
//die($response->get_error_message());
}

// cache for an hour
set_transient(‘cfTwitterFollowers’, $numberOfFollowers, 1*60*60);
update_option(‘cfNumberOfFollowers’, $numberOfFollowers);
}

return $numberOfFollowers;
}


Aqui eu uso pra mostar os seguidores :

<div class=”entry-social”>
<div class=”twitter”>
<?php echo getTwitterFollowers(‘username’); ?>  Seguidores
</div>
</div>

 

O número aparece 43345. TUDO JUNTO Como formato pra aparecer 43.345?

 

Muito obrigado desde já!

Link to post
Share on other sites

3 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      148691
    • Total Posts
      644531
×
×
  • Create New...