MrXander Posted October 30, 2007 Share Posted October 30, 2007 Hi there, What I need to do is display the last 8 values from a database on my site, which is fine, but the question is, I want to remove the first part of the data. Basically, the thing I need to display is a URL, for example, <b>http://domain.com/</b>2596. I need to be able to remove the "http://domain.com/" from showing on the main page, and only keep the numbers afterwards. Is there a way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/75406-solved-removing-text-from-a-given-value/ Share on other sites More sharing options...
GingerRobot Posted October 30, 2007 Share Posted October 30, 2007 You could explode by the forward slash, and select the last element of the array: <?php $sql = "SELECT `url` FROM `yourtable` LIMIT 8";//obviously you'll want an order by statement in there, but im not sure how you're defining last 8 $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc()){ $bits = explode('/',$row['url']); $num = $bits[count($bits)-1];//get the last part of the array echo $num.'<br />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/75406-solved-removing-text-from-a-given-value/#findComment-381456 Share on other sites More sharing options...
MrXander Posted October 30, 2007 Author Share Posted October 30, 2007 Lovely, cheers Ben! Quote Link to comment https://forums.phpfreaks.com/topic/75406-solved-removing-text-from-a-given-value/#findComment-381462 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.