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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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); Quote Link to comment 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 Quote Link to comment 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.