iGuest 3 Report post Posted March 9, 2005 Can someone tell me, how to getfirst 5 characters from the some word i have i my database (mysql)example:$word = VerylongLonglognword_or_sentence;$short_w= veryl...; Share this post Link to post Share on other sites
miCRoSCoPiC^eaRthLinG 0 Report post Posted March 9, 2005 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...; 58012[/snapback] I'm going to use the variables that you've used. Say your $word contains the very long word. Now: $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. Share this post Link to post Share on other sites
iGuest 3 Report post Posted March 10, 2005 tnx, its working! Share this post Link to post Share on other sites
Spectre 0 Report post Posted March 28, 2005 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. Share this post Link to post Share on other sites
Spectre 0 Report post Posted March 28, 2005 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. Share this post Link to post Share on other sites