473,624 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 45372
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($oldstri ng,0,20);
echo $newstring;

HTH

"Ricki Susic" <ri************ *@webfabrikken. net> wrote in message
news:3f******** *************** @dread12.news.t ele.dk...
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($oldstri ng,0,20);
echo $newstring;

HTH

"Ricki Susic" <ri************ *@webfabrikken. net> wrote in message
news:3f******** *************** @dread12.news.t ele.dk...
> 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($oldstri ng,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($oldstri ng,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
2260
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
16092
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 type. Now the problem is how to print the binary format of that charater to the standard output. It seems a common task but I just cannot find the appropriate method from the documentation. Thanks a lot.
8
7572
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
3593
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 first using C function on that stream. And the specific orientation functions should not be applied to the stream that have other orientation.
2
11010
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 10,) When, you have a list of characters and want them to be printed together a string using a for loop, there was observation that no matter what there was space coming between the characters. No split or join methods helped. print e, a b c
2
3734
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 textbox, but the \x0D keeps performaing the CR I dont want the CR to occur, i want the string to print the actual
38
2700
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
4896
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 need to know instead of typing so many %s can i write %6s in python, as | we do in C progm. I hate to tell you this, but "%6s" in C does NOT print 6 strings. It prints 1 string, right justified, in no less that 6 characters.
2
6700
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 of Chinese characters, on my machine I installed language pack and currently set language as Chinese PRC but still it's not working. Option Explicit Private Type DOCINFO pDocName As String pOutputFile As String pDatatype As String
0
8240
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8175
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8625
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7168
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1487
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.