I’m using the following preg_match:
preg_match( '!<div class="thumblock ">(.*)</div>!si' , wp_gdsr_render_article_thumbs(0, false, "", 0, "", false) , $n );
$thumbs_string = strip_tags( $n[1] );
To extract the number between the span tags:
<div class="thumblock ">
<span class="rating-result">
<div id="gdsr_thumb_text_12_a" class="gdt-size-20 voted inactive gdthumbtext">+1</div>
</span>
<div class="ratingtext ">
<div class="raterclear"></div>
</div>
(in the example above, result is a string: “+1”)
So I tried converting it into an integer with this:
$thumbs_number = (int)$thumbs_string;
which is used in this function:
function get_rating_class($thumbs_number) {
if ($thumbs_number < 0) return ' bad';
if ($thumbs_number < 2) return ' average';
if ($thumbs_number < 4) return ' good';
return ' excellent';
}
function rating_class($thumbs_number) {
echo get_rating_class($thumbs_number);
}
to output a div class:
<div class="topic-like-count<?php rating_class($thumbs_number); ?>">
I even did var_dump():
<h2><?php var_dump($thumbs_string); ?></h2>
<h2><?php var_dump($thumbs_number); ?></h2>
and the results were:
string(2) "+1" and int(1) respectively (I directly copy/pasted them here).
But no div class is being output.
Any suggestion to fix this?
EDIT:
The class is indeed being output in the HTML source, but it isn’t having any effect (and my stylesheet is not being cached). I have another version of the function which doesn’t add an extra div around the span tags, and that one works but unfortunately I need that div.
If the class name is being displayed in the HTML then the PHP code is fine. The stylesheet is likely the problem.