<?php function lastinteger($item) { preg_match_all('/data-id=[\"\']([1-9]+)[\"\']/',$item,$array); $out = end($array); return $out[0]; } $path1 = "<span class='span1' data-id='2'>lorem ipsum</span>"; $path2 = "<span class='span2' data-id='14'>lorem ipsum</span>"; $a = lastinteger($path1); //2 $b = lastinteger($path2); //14 echo $a." ".$b;
You have javascript disabled. You will not be able to edit any code.