By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,967 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,967 IT Pros & Developers. It's quick & easy.

print the first 20 characters of a string

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.