manalnor Posted August 18, 2011 Share Posted August 18, 2011 Hello dear friends, If i've called something from database table say for example $title = "hello world i love you"; Now i want to show it as following hello world i love you this mean i wanna say after any 1st word set all the rest as superscripted text thanks *sorry if i can't explain more better Link to comment https://forums.phpfreaks.com/topic/245151-just-1st-word-gets-superscripted/ Share on other sites More sharing options...
WebStyles Posted August 18, 2011 Share Posted August 18, 2011 if it's always after the first word you could use strpos to detect where the first space is. Link to comment https://forums.phpfreaks.com/topic/245151-just-1st-word-gets-superscripted/#findComment-1259165 Share on other sites More sharing options...
manalnor Posted August 18, 2011 Author Share Posted August 18, 2011 @WebStyles thank you so much, i've been thinking of same idea but didn't knew which function should i use. it was very helpful to me Link to comment https://forums.phpfreaks.com/topic/245151-just-1st-word-gets-superscripted/#findComment-1259166 Share on other sites More sharing options...
Psycho Posted August 18, 2011 Share Posted August 18, 2011 I made this a function so you can reuse it and modify the output if needed. I don't think using <SUP> tags is the "proper" way to do this any more. function superscriptAllButFirst($string) { $index = strpos($string, ' ') + 1; $firstWord = substr($string, 0, $index); $remainingWords = substr($string, $index); return "$firstWord<sup>{$remainingWords}</sup>"; } $text = "Hello world I love you"; echo superscriptAllButFirst($text); Link to comment https://forums.phpfreaks.com/topic/245151-just-1st-word-gets-superscripted/#findComment-1259168 Share on other sites More sharing options...
manalnor Posted August 18, 2011 Author Share Posted August 18, 2011 @mjdamato Your function is working very perfect and exactly like what i want, i will study every part of it to learn more. thank you a lot shokran Link to comment https://forums.phpfreaks.com/topic/245151-just-1st-word-gets-superscripted/#findComment-1259175 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.