sandy1028 Posted April 30, 2009 Share Posted April 30, 2009 Hi, Can anyone please tell me how to select only last value i.e 72 from this string <b>1</b> - <b>10</b> of about <b>72</b> Quote Link to comment https://forums.phpfreaks.com/topic/156226-select-digit/ Share on other sites More sharing options...
ILMV Posted April 30, 2009 Share Posted April 30, 2009 $arr=split('<br>',$list); $last_item=str_replace('</br>', $arr[2]); echo($last_item); Not perfect, but that should do it. Quote Link to comment https://forums.phpfreaks.com/topic/156226-select-digit/#findComment-822491 Share on other sites More sharing options...
madhuri Posted April 30, 2009 Share Posted April 30, 2009 Hi , Please try below code which will give you the result as 72. <?php $str = '<b>1</b> - <b>10</b> of about <b>72</b>'; $str1 = strlen($str); print substr($str,$str1-6,$str1-4); ?> Quote Link to comment https://forums.phpfreaks.com/topic/156226-select-digit/#findComment-822493 Share on other sites More sharing options...
ILMV Posted April 30, 2009 Share Posted April 30, 2009 Sorry madhuri, but what happens when the number at the end is not 2 characters long? 137 for example would return 37 9 for example would return >9 ILMV Quote Link to comment https://forums.phpfreaks.com/topic/156226-select-digit/#findComment-822496 Share on other sites More sharing options...
ignace Posted April 30, 2009 Share Posted April 30, 2009 $arr=split('<br>',$list); $last_item=str_replace('</br>', $arr[2]); echo($last_item); Not perfect, but that should do it. str_replace() takes 3 arguments not 2, thus: $last_item = str_replace('</br>', '', $arr[2]); Quote Link to comment https://forums.phpfreaks.com/topic/156226-select-digit/#findComment-822499 Share on other sites More sharing options...
sasa Posted April 30, 2009 Share Posted April 30, 2009 try preg_match('~<b>\d+</b> - <b>\d+</b> of about <b>(\d+)</b>~', $test, $out); print_r($out); not tested Quote Link to comment https://forums.phpfreaks.com/topic/156226-select-digit/#findComment-822564 Share on other sites More sharing options...
cringe Posted April 30, 2009 Share Posted April 30, 2009 Not tested... $string = '<b>1</b> - <b>10</b> of about <b>72</b>' ; $stringArray = explode('<b>',$string) ; $lastInt = intval(end($stringArray), 10) ; Quote Link to comment https://forums.phpfreaks.com/topic/156226-select-digit/#findComment-822579 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.