Jul 25, 2008

1st 5 Chars - 1st 5 chars from the word

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

1st 5 Chars - 1st 5 chars from the word

ivanc081
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...;

Reply

miCRoSCoPiC^eaRthLinG
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. smile.gif

 

 

 


Reply

ivanc081
tnx, its working!

Reply

Spectre
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.

Reply

Spectre
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.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : 1st chars 1st chars


    Looking for 1st, 5, chars, 1st, 5, chars, word

Searching Video's for 1st, 5, chars, 1st, 5, chars, word
advertisement



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