bsamson Posted January 7, 2008 Share Posted January 7, 2008 Alright I have searched and searched. So here goes ... $number = "123.456.7890" I need to grab "7890". So: $lastfour = "7890" How do I do this? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/84928-how-to-store-last-4-characters-of-a-string/ Share on other sites More sharing options...
Ken2k7 Posted January 7, 2008 Share Posted January 7, 2008 Is the number after the last "." always 4 digits? <?php $arr = explode(".",$number); echo $arr[count($arr)-1]; ?> Link to comment https://forums.phpfreaks.com/topic/84928-how-to-store-last-4-characters-of-a-string/#findComment-433010 Share on other sites More sharing options...
drummer101 Posted January 7, 2008 Share Posted January 7, 2008 <?php substr($string, -4) ?> Link to comment https://forums.phpfreaks.com/topic/84928-how-to-store-last-4-characters-of-a-string/#findComment-433012 Share on other sites More sharing options...
bsamson Posted January 7, 2008 Author Share Posted January 7, 2008 Thanks. Just one more thing ... Here's the situation: Users enter a page and enter the last 4 of their phone number. I have a DB w/ this info. So for example: Field: Phone Contents: 123.456.7890 If a user enters "7890" I need to create a query that finds the above field. How do I go about doing this? Thanks again in advance! Link to comment https://forums.phpfreaks.com/topic/84928-how-to-store-last-4-characters-of-a-string/#findComment-433018 Share on other sites More sharing options...
GingerRobot Posted January 7, 2008 Share Posted January 7, 2008 SELECT * FROM tbl WHERE SUBSTRING(col,-4) = '7890' Link to comment https://forums.phpfreaks.com/topic/84928-how-to-store-last-4-characters-of-a-string/#findComment-433019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.