I suspect you're forgetting that the output is a HTML tag, so won't show in the browser (unless you do a view source). Try this:
<?php
$gettotal = "<span class='totalpages'>";
$fine = preg_match("/^<span class='totalpages'>/", $gettotal, $matches);
printf("<pre>%s</pre>", htmlentities(print_r($matches, 1)));
?>