I'd recommend the following XPath, as suggested in this question:
//span[contains(concat(" ", normalize-space(@class), " "), " ui_bubble_rating ")]
You can then retrieve the number you're looking for with a regular expression that looks for a series of digits preceded by bubble_
:
$ratingsElements = $xp->query('//span[contains(concat(" ", normalize-space(@class), " "), " ui_bubble_rating ")]');
if ($ratingsElements->length > 0) {
$firstRatingElement = $ratingsElements->item(0);
if (preg_match('/(?<=\bbubble_)\d+/', $firstRatingElement->getAttribute('class'), $matches)) {
$datas[$activity]['rating'] = $matches[0]; // 45
}
}
Demo