RE: [PHP] First Character of a string.
| From: | Ben Wiechman | Date: | Mon, 09 Oct 2000 21:23:32 +0000 |
| Subject: | RE: [PHP] First Character of a string. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-19245@lists.php.net to get a copy of this message | ||
-----Original Message-----
From: kevin@hermes.kdi.com [mailto:kevin@hermes.kdi.com]On Behalf Of
kevin@oceania.net
Sent: Monday, October 09, 2000 1621 Neteru
To: Jitterbug
Cc: php-general@lists.php.net
Subject: Re: [PHP] First Character of a string.
Jitterbug wrote:
>
> On Sun, 8 Oct 2000 19:19:05 +0100, you wrote:
>
> >
> >> <?
> >> $firstname ="Brian";
> >> $firstinitial="
> >> ?>
> >> here i want to parse out just the B from Brian with out hard coding it
in
> >> <?
> >> ";
> >> echo $firstname,"<BR>";
> >> echo $firstinitial,"<BR>";
> >> ?>
> >
> >$firstinitial= substr($firstname,1,1);
> >
> >James
>
> should be
>
> $firstinitial = substr($firstname,0,1);
>
> I like
>
> $firstinitial = $firstname[0];
Using this method, can I get the first 3 chars?
$firstinitial = substr($firstname,0,3);
$firstinitial = $firstname[?];
$firstinitial = $firstname[0];
$firstinitial .= $firstname[1];
$firstinitial .= $firstname[2];
Although in this case it would probably be better to just use the substr()
function. Much easier should you decided you want to change the number of
letters you are pulling out of the string.
Ben
--
Kind regards
Kevin Waterson
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net