sungpeng Posted April 23, 2009 Share Posted April 23, 2009 $hello="1 fish meat rice"; echo "$hello"; display : 1 fish meat rice Check Can the display be ignore the first character "1" and display the rest. For this case only display only "fish meat rice". Quote Link to comment https://forums.phpfreaks.com/topic/155309-ignore-first-character-and-display-the-rest/ Share on other sites More sharing options...
genericnumber1 Posted April 23, 2009 Share Posted April 23, 2009 Look into using substr and trim along with your echo statement. Quote Link to comment https://forums.phpfreaks.com/topic/155309-ignore-first-character-and-display-the-rest/#findComment-817103 Share on other sites More sharing options...
sungpeng Posted April 23, 2009 Author Share Posted April 23, 2009 hi generic, can help draft it out? pls Quote Link to comment https://forums.phpfreaks.com/topic/155309-ignore-first-character-and-display-the-rest/#findComment-817112 Share on other sites More sharing options...
sungpeng Posted April 23, 2009 Author Share Posted April 23, 2009 $hello="category American apple"; echo end(explode(' ', $hello)); The above code can display the last wordings "apple". I also need a code to ignore the first wordings and display the rest. In this case, it will display "American apple" and ignore "category". Quote Link to comment https://forums.phpfreaks.com/topic/155309-ignore-first-character-and-display-the-rest/#findComment-817396 Share on other sites More sharing options...
mikesta707 Posted April 23, 2009 Share Posted April 23, 2009 the substr() function would probably help you out. This function takes three parameters, the string, the start point and the length, the latter which is optional. If you did the following code $text = "Hello World"; $text = substr($text, 0, 5); echo $text; you would output hello. If you want to take off the first letter, then you want to take the substring starting with the second character right? so the following code: $hello="1 fish meat rice"; $hello = substr($hello, 1); echo $hello; would do what you want because it takes everything from the 2nd character (or the character with position 1) on Hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/155309-ignore-first-character-and-display-the-rest/#findComment-817535 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.