| | Can someone tell me, how to get first 5 characters from the some word i have i my database (mysql) example: $word = VerylongLonglognword_or_sentence; $short_w= veryl...; |
|
|
QUOTE(ivanc081 @ Mar 9 2005, 04:31 PM) Can someone tell me, how to get first 5 characters from the some word i have i my database (mysql) example: $word = VerylongLonglognword_or_sentence; $short_w= veryl...; I'm going to use the variables that you've used. Say your $word contains the very long word. Now: CODE $short_w = substr ( $word, 0, 5 ); This should extract the first 5 characters from your $word and store it in $short_w. This is assuming you are using PHP with MySQL. If you want a little more explanatin - the substr function extracts a substring from your string based on the parameters provided to it. General form is: susbstr ( LargeString, StartPosition, LengthOfSubString ) - this extracts a string of length LengthOfSubString starting at position StartPosition from your original string LargeString. Hope this helps.
tnx, its working!
You can also use $variable[length], eg. $variable[4]. Remember that the starting position is 0, not 1, so this would extract the first 5 characters.
Argh, what am I thinking? That would select the character, not the first 5 characters. It's 3:00am, so you'll have to excuse my incoherence.
|
|
![]() 1st 5 Chars - 1st 5 chars from the word |
| ADD REPLY / Got an Opinion! | Remove these ADs! | RAPID SEARCH! | Free Web Hosting | [X] |
|
Express your Opinions, Thoughts or Contribute more info. to help others. Ask your Doubts & Queries to get answers, So that "Together We can help others!" |
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP. | 500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE |
|