Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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

Posts: 468
Trades: 0
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!
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
 
Register now for full access!
Old 11-13-2007, 04:43 PM Re: First Letter
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
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
?>
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

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
Trades: 1
how about an easyer method
$string='testString';
$firstLetter=$string[1];
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
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: 219
Name: Rob
Location: UK
Trades: 0
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
Trades: 1
right ... sorry my bad
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
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: 410
Name: Harry Burt
Location: Colchester, Essex, England
Trades: 0
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 :
Please login or register to view this content. Registration is FREE


New Dreamed Up Web Design:
Please login or register to view this content. Registration is FREE

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
Trades: 1
what problems ?
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
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: 410
Name: Harry Burt
Location: Colchester, Essex, England
Trades: 0
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 :
Please login or register to view this content. Registration is FREE


New Dreamed Up Web Design:
Please login or register to view this content. Registration is FREE
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:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
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 Search this Thread
Search this Thread:

Advanced Search

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

BB 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.28445 seconds with 12 queries