> $name = "John";
>
> how can i echo the first letter only so the result on the browser will be "J"
echo $name{0};
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
echo $name[0];
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Ahmed Abdel-Aliem wrote:
hi
if i have for example this variable
$name = "John";
how can i echo the first letter only so the result on the browser will be "J"
can anyone help ?
echo $name{0};
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
$name = "John";
echo $name{0};
you can also look into substr()
- Original Message -
From: "Ahmed Abdel-Aliem" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, December 20, 2004 12:59 PM
Subject: [PHP] first letter
> hi
> if i have for example this variable
>
> $name = "John";
echo $name{0};
See http://us2.php.net/manual/en/function.substr.php for more...
> -Original Message-
> From: Ahmed Abdel-Aliem [mailto:[EMAIL PROTECTED]
> Sent: Monday, December 20, 2004 1:00 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] first letter
>
> hi
> if i have for example this
[begin untested code]
$name = 'John';
echo substr($fname,0,1);
[end untested code]
That will print the first letter of the variable $name.
substr(string,int start, int length);
int length is optional.
On Mon, 20 Dec 2004 19:59:49 +0200, Ahmed Abdel-Aliem <[EMAIL PROTECTED]> wrote:
> hi
> if i
if i have for example this variable
$name = "John";
how can i echo the first letter only so the result on the browser will
be "J"
echo $name[0];
You could also use the substr() function.
Larry
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Not sure if it's deprecated or not, but you can reference it as an array:
echo $name[0];
or the more accepted method:
echo substr($name,0,1);
>
> From: Ahmed Abdel-Aliem <[EMAIL PROTECTED]>
> Date: 2004/12/20 Mon PM 12:59:49 EST
> To: [EMAIL PROTECTED]
> Subject: [PHP] first letter
>
> hi
> if
Ahmed Abdel-Aliem wrote:
hi
if i have for example this variable
$name = "John";
how can i echo the first letter only so the result on the browser will be "J"
can anyone help ?
$name[0]
--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php
Check this out...
http://us2.php.net/manual/en/function.substr.php
- Original Message -
From: Ahmed Abdel-Aliem <[EMAIL PROTECTED]>
Date: Monday, December 20, 2004 12:59 pm
Subject: [PHP] first letter
> hi
> if i have for example this variable
>
> $name = "John";
>
> how can i echo the
10 matches
Mail list logo