I need to retrive a selected part from a url . I’ve used substr method and i’ve successfully get the character. But my issue is that ,this is my sample url localhost/xxxxxxx/sugar_daddy_member-1.xml i need to retrive the last number in the url. By using this below given code i can sucessfully get the number but if two digit number comes in the url i can retrive only one number.
JavaScript
x
$page = 'sugar_daddy_member-10';
$last_char = substr($page, 19, 1);
Advertisement
Answer
You can use the strrpos
function to find the dash.
JavaScript
<?php
$page = 'sugar_daddy_member-10';
$idx = strrpos($page, '-');
$last_char = substr($page, $idx+1);
echo ($last_char);
?>
Output
JavaScript
10