Extract the last characters
<p>I'm trying to extract the last two digits in a string. First I remove any spaces or special characters and replace them with a hyphen then if there are two hyphens following each other, I remove them. ext I remove any trailing hyphens. Next I want to extract the last two characters after the lat hyphen in the string. For example how do I extract the last characters in this string i.e <code>1</code> after the last hyphen? <code>awesome-page-1</code>. My code is here </p>

<pre><code>$string = 'awesome page@1';
  $slug = preg_replace('/[^a-zA-Z0-9]/', '-', $string);//replace spaces and special characters with space
        $slug = preg_replace('#-{2,}#', '-', $slug);//two hyphens following each other
        $slug = trim($slug, '-');//remove trailing hyphens
</code></pre>
