Gayner Posted October 12, 2009 Share Posted October 12, 2009 I know this is possible but let's say my username is Mikey29 I want to call a function or class of php that reads only last 29 on that and if it equals "29" then it echos " HELLO I HAVE A NAME " Possible? Thanks i think it's called strpos or something? Quote Link to comment https://forums.phpfreaks.com/topic/177375-solved-php-help-reading-last-1-2-characters-in-a-piece-of-text-or-variable/ Share on other sites More sharing options...
farkewie Posted October 12, 2009 Share Posted October 12, 2009 $name = "test29"; if (substr($name, strlen($name) - 2) == "29"){ //Success } Could also use regex Quote Link to comment https://forums.phpfreaks.com/topic/177375-solved-php-help-reading-last-1-2-characters-in-a-piece-of-text-or-variable/#findComment-935213 Share on other sites More sharing options...
Alex Posted October 12, 2009 Share Posted October 12, 2009 Alternatively you could use negative values in substr(), substr($name, -2); Quote Link to comment https://forums.phpfreaks.com/topic/177375-solved-php-help-reading-last-1-2-characters-in-a-piece-of-text-or-variable/#findComment-935215 Share on other sites More sharing options...
Gayner Posted October 12, 2009 Author Share Posted October 12, 2009 OH MAn this is epic! now instead of making a whole new field name for it i can just use this and add some random text to a existing field for a certain user then use that code and it will work for only that user instead of making a whole freakin new row/field name in the table!! This is epic thank u sir!! Quote Link to comment https://forums.phpfreaks.com/topic/177375-solved-php-help-reading-last-1-2-characters-in-a-piece-of-text-or-variable/#findComment-935216 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.