469,280 Members | 2,449 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,280 developers. It's quick & easy.

print the first 20 characters of a string

Hi,

Is there a function in php that makes it possible to limit the output of a
text-string; meaning only print the first e.g. 20 characters of the string?

Ricki
Jul 16 '05 #1
5 45108
Ricki Susic wrote on Thursday 28 August 2003 01:06:
Is there a function in php that makes it possible to limit the output of a
text-string; meaning only print the first e.g. 20 characters of the
string?


Have you bothered to look at string functions in the documentation?
http://www.php.net/manual/en/function.substr.php

--
Business Web Solutions
ActiveLink, LLC
www.active-link.com/intranet/
Jul 16 '05 #2
Have you bothered to look at string functions in the documentation?
http://www.php.net/manual/en/function.substr.php


Yes, I have looked in the manual but I'm sure that I'm not the first person
to get a bit confused trying to look up a certain solution in the php.net
manual. It is very hard to find the needed function when you don't know what
to look for!
You know what I mean?

Ricki
Jul 16 '05 #3
substring your string starting at 0 and going for 20 and then echo the
result.

eg.
$newstring = substr($oldstring,0,20);
echo $newstring;

HTH

"Ricki Susic" <ri*************@webfabrikken.net> wrote in message
news:3f***********************@dread12.news.tele.d k...
Have you bothered to look at string functions in the documentation?
http://www.php.net/manual/en/function.substr.php
Yes, I have looked in the manual but I'm sure that I'm not the first

person to get a bit confused trying to look up a certain solution in the php.net
manual. It is very hard to find the needed function when you don't know what to look for!
You know what I mean?

Ricki

Jul 16 '05 #4
On Thu, 28 Aug 2003 09:17:48 +0000, Peter Taurins wrote:
substring your string starting at 0 and going for 20 and then echo the
result.

eg.
$newstring = substr($oldstring,0,20);
echo $newstring;

HTH

"Ricki Susic" <ri*************@webfabrikken.net> wrote in message
news:3f***********************@dread12.news.tele.d k...
> Have you bothered to look at string functions in the documentation?
> http://www.php.net/manual/en/function.substr.php


Yes, I have looked in the manual but I'm sure that I'm not the first

person
to get a bit confused trying to look up a certain solution in the php.net
manual. It is very hard to find the needed function when you don't know

what
to look for!
You know what I mean?

Ricki

You can also do this in a single step:

echo substr($oldstring,0,20);

Two advantages of consolidating statements in order to eliminate temporary
variables are:
1). fewer lines of code and variables to analyze in the future when it is time
to make changes to the program, and

2). it is more efficient since the PHP runtime doesn't have to create a
variable and load it every time the program runs. The benefits are both
faster execution speed and more compact programs.
Jul 16 '05 #5
You can also do this in a single step:

echo substr($oldstring,0,20);

Two advantages of consolidating statements in order to eliminate temporary
variables are:
1). fewer lines of code and variables to analyze in the future when it is time to make changes to the program, and

2). it is more efficient since the PHP runtime doesn't have to create a
variable and load it every time the program runs. The benefits are both
faster execution speed and more compact programs.


I see your point! Thank you;-)

Ricki
Jul 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by opt_inf_env | last post: by
12 posts views Thread by neutrino | last post: by
2 posts views Thread by Phoe6 | last post: by
2 posts views Thread by Peted | last post: by
3 posts views Thread by Cameron Simpson | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.