jeff5656 Posted April 9, 2011 Share Posted April 9, 2011 Can someone help me with this. I think I need to use substr: how do I only echo out everything after the period ( ".") for example if I have "table.birthday" I want to echo: "birthday" Quote Link to comment https://forums.phpfreaks.com/topic/233193-echo-up-to-a-certain-character/ Share on other sites More sharing options...
joel24 Posted April 9, 2011 Share Posted April 9, 2011 find the position of the . then return the string after that i.e. $string = 'table.birthday'; $position = strpos('.',$string); $newString = substr($string, $position); echo $newString; Quote Link to comment https://forums.phpfreaks.com/topic/233193-echo-up-to-a-certain-character/#findComment-1199219 Share on other sites More sharing options...
jeff5656 Posted April 9, 2011 Author Share Posted April 9, 2011 That didnt work. When i echout out NewString I got the original string: table.birthday When I echoed out $position, it was blank. Quote Link to comment https://forums.phpfreaks.com/topic/233193-echo-up-to-a-certain-character/#findComment-1199228 Share on other sites More sharing options...
ted_chou12 Posted April 9, 2011 Share Posted April 9, 2011 $string = 'table.birthday'; $position = strpos($string, '.'); echo substr($string, $position); //with a dot echo substr($string, $position + 1); //without a dot joel24 typed too fast, the inputs are switched Ted Quote Link to comment https://forums.phpfreaks.com/topic/233193-echo-up-to-a-certain-character/#findComment-1199229 Share on other sites More sharing options...
joel24 Posted April 10, 2011 Share Posted April 10, 2011 joel24 typed too fast, the inputs are switched that I did, cheers for the fix up Quote Link to comment https://forums.phpfreaks.com/topic/233193-echo-up-to-a-certain-character/#findComment-1199513 Share on other sites More sharing options...
3raser Posted April 10, 2011 Share Posted April 10, 2011 Here is a shorter way: <?php $old = "table.birthday"; $new = end(explode('.', $old)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/233193-echo-up-to-a-certain-character/#findComment-1199528 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.