Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert number from this code into php?

Tags:

php

I'm trying to insert the number only from this:

<span class="fb-comments-count" data-href="http://example.com/"></span>comments

into some existing php code:

<span class="meta_facebook_comments">
   <i class="fa fa-comments"></i> 
        <?php 
            echo "Comments";
        ?>
</span>

and for the love of life I can't figure it out?

i.e. to display something like this:

<i class="fa fa-comments"></i> 2 Comments

for example..

looking for some advice, Thanks

like image 759
Hopelessone Avatar asked Nov 10 '22 11:11

Hopelessone


1 Answers

You can use jquery prepend to add value before "comments" text:

$(".fa .fa-comments").prepend("2 ");  

The results will be

2 comments

EDIT: based of OP's comment-> to transfer data from one element to another, use this method:

var number_of_comments = $(".fb-comments-count").text(); //get number of comments  
$(".fa .fa-comments").prepend(number_of_comments); //add comment count to another element  

Please see this working demo

like image 133
Luthando Ntsekwa Avatar answered Nov 14 '22 22:11

Luthando Ntsekwa