Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 15th, 2003, 08:50 AM
Authorized User
 
Join Date: Jun 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to starsol
Default Obtaining a variable from the first letter...

Hi,

I've been looking at the explode function on the PHP manual website but it's not giving me an answer to this.

How can the first letter of a variable be taken to create a separate variable, for example, if $name is 'Robert', how could I get $first_letter to be 'R'?

Thanks in advance, and best wishes,
Rupe

Rupe Parnell
www.starsol.co.uk
__________________
Rupe Parnell
www.starsol.co.uk
 
Old August 15th, 2003, 08:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

$first_letter = substr($name,0,1);

 
Old August 15th, 2003, 09:23 AM
Authorized User
 
Join Date: Jun 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to starsol
Default

Thanks Jonax !

Rupe Parnell
www.starsol.co.uk
 
Old August 18th, 2003, 01:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This might be easier/shorter:

$first_letter = $name[0];

Remember, you can use array-index notation to access specific characters in a text string!


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
obtaining handle of the window C# nirmal_thapa C# 0 January 30th, 2007 09:10 AM
Obtaining User Logon dearnne Access 1 September 2nd, 2004 01:39 PM
Programmatically obtaining info on Excel DLL's tcarnahan Excel VBA 0 August 14th, 2004 11:45 PM
Programmatically obtaining info on macros tcarnahan Access VBA 0 August 14th, 2004 11:42 PM
Obtaining information from a form Ashleek007 PHP How-To 1 March 1st, 2004 09:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.