473,372 Members | 828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

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 45355
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: opt_inf_env | last post by:
Hello, Should be a simple question... Do you know why the following two lines print not "123" but only "1"? $aaa = 123; print $aaa;
12
by: neutrino | last post by:
Greetings to the Python gurus, I have a binary file and wish to see the "raw" content of it. So I open it in binary mode, and read one byte at a time to a variable, which will be of the string...
8
by: vijay | last post by:
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct llnode { char *info;
1
by: iwongu | last post by:
Hi, I have a question about std::wcout and its underlying C functions. According to C99, a stream have an orientation type that is one of byte-oriented or wide-one, and it is determined by the...
2
by: Phoe6 | last post by:
print and softspace in python In python, whenever you use >>>print statement it will append a newline by default. If you don't want newline to be appended, you got use a comma at the end (>>>print...
2
by: Peted | last post by:
Hi im sending this string to a device String cmd = ""N1\x0D") this device needs the esc \x0D on the end where you see it After i have sent this string i want to print it our to a rich...
38
by: ssecorp | last post by:
char* reverse(char* str) { int length = strlen(str); char* acc; int i; for (i=0; i<=length-1; i++){ acc = str; } return acc; }
3
by: Cameron Simpson | last post by:
On 18Aug2008 11:58, Beema Shafreen <beema.shafreen@gmail.comwrote: | In my script i have to print a series of string , so | | print "%s\t%s\t%s\t%s\t%s\t%s\t" %("a","v","t","R","s","f") | | I...
2
by: Flying Kite | last post by:
Hi All, I want to know how to print chinese characters on Zebra Printer, following code working fine with English string, but it's not working for Chinese string. It shows ASCII characters instead...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.