Reply
First Letter
Old 11-13-2007, 04:22 PM First Letter
evans123's Avatar
Ultra Talker

Posts: 269
How can i take only the first letter of a string

e.g.

absjskw

and take just the first letter, its gunna be a dynamic string as well!
__________________
SoldierExteme.com - Free MMORPG - sign-up today!
Backthebulls.com - Free online games (mad_willsy's)
Msnextra.co.uk - Msn Items
evans123 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 11-13-2007, 04:43 PM Re: First Letter
rogem002's Avatar
Webmaster Talker

Posts: 579
Name: Mike
Location: United Kingdom
The substr() function

http://uk.php.net/manual/en/function.substr.php

PHP Code:
<?php
$rest 
substr("abcdef", -1);    // returns "f"
$rest substr("abcdef", -2);    // returns "ef"
$rest substr("abcdef", -31); // returns "d"
?>
So you would want:
PHP Code:
<?php
echo substr('abcdef'01);  // a
?>
__________________
Website Services
PHP Code:
if(Added_Talkupation($post) == TRUE){iHug($you);} 

Last edited by rogem002 : 11-13-2007 at 04:45 PM.
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 11-14-2007, 05:47 AM Re: First Letter
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
how about an easyer method
$string='testString';
$firstLetter=$string[1];
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 11-14-2007, 07:49 AM Re: First Letter
maxxximus's Avatar
Extreme Talker

Posts: 176
Name: Rob
Location: UK
Quote:
Originally Posted by solomongaby View Post
how about an easyer method
$string='testString';
$firstLetter=$string[1];
Not quite right
First letter would be 0

$firstLetter=$string[0];
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 11-14-2007, 08:58 AM Re: First Letter
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
right ... sorry my bad
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 11-14-2007, 01:43 PM Re: First Letter
Foundationflash's Avatar
Ultra Talker

Posts: 403
Name: Harry Burt
Location: Colchester, Essex, England
Obviously there might be problems with that second way of doing things (in terms of dynamicity/dynamism), but it would work here.
__________________
Foundation Flash tutorials : www.foundation-flash.com

New Dreamed Up Web Design: www.dreamedupdesign.com

Last edited by Foundationflash : 11-14-2007 at 01:48 PM.
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Old 11-14-2007, 01:47 PM Re: First Letter
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
what problems ?
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 11-14-2007, 01:53 PM Re: First Letter
Foundationflash's Avatar
Ultra Talker

Posts: 403
Name: Harry Burt
Location: Colchester, Essex, England
All I meant was that, say, if you wanted to dynamically pick how many letter to take using substr() would be coded more easily (no loops etc), but the more I think about it, the smaller the difference seems to me to be. Sorry...
__________________
Foundation Flash tutorials : www.foundation-flash.com

New Dreamed Up Web Design: www.dreamedupdesign.com
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Old 11-14-2007, 11:35 PM Re: First Letter
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Wireless Audio
Posts: 2,314
Name: Keith Marshall
Location: West Hartford, CT
Quote:
Originally Posted by maxxximus View Post
Not quite right
First letter would be 0

$firstLetter=$string[0];
To yet add another insight, I think $firstLetter = $string{0}; would be a better choice since $string is not an array (I think the square brackets may issue a warning if I'm correct).
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to First Letter
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15722 seconds with 13 queries