iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 12, 2008
Film Makers, Bands and Comedians Welcome on MySpace
About
 
May 12, 2008
Software Engineering for Ajax
WebReference.com
 
May 12, 2008
What is the Head Tag For?
About
 
May 11, 2008
Improving accessibility for motor impaired users
WebDevTips UK
 
May 11, 2008
10 ways to orientate users on your site
WebDevTips UK
 
May 11, 2008
Web Design Clinic - Rros restoration camp 2006
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /PHP

String manipulating functions 

  Views:    2915
  Votes:    0
by Diego Botello 12/08/03 Rating: 

Synopsis:

This is a review of some of PHP string functions.
Pages: 
The Article

Wrapping words in a paragraph 

To wrap words in a paragraph you make use of the wordwrap function. wordwrap accepts a string that contains the text to wrap, the desired width(optional), the string breaking method(optional), and whether to cut the last word or  not(optional). The following example illustrates its use.

$para="The number in the shirt is 35";

$wrapped= wordwrap($para, 10, "<br>");

print "$wrapped";

This will output:

The number
in the
shirt is
35

In the above code $para is the text to wrap, 10 is the length of the line, and <br> is our desired line break (we can also use \n). To cut the line at a maximum desired length we would have to ad a, 1 to the wordwrap function above, see the following example.

$wrapped= wordwrap($para, 3, "<br>", 1);

This will output:

The
num
ber
in
the
shi
rt
is
35

Changing string case

There are several functions to change strings to uppercase or lowercase characters. To make the first character of a string uppercase we use ucfirst. To change all the first characters on every word we use ucwords. strtoupper changes all characters to uppercase. To change all the characters of a string to lowercase we use strtolower. The following example illustrates these functions.

<?php

$para="the number in the shirt is 35";

print ucfirst($para)."<br>";

print ucwords($para)."<br>";

print strtoupper($para)."<br>";

print strtolower($para)."<br>";

?> 

This will output:

The number in the shirt is 35
The Number In The Shirt Is 35
THE NUMBER IN THE SHIRT IS 35
the number in the shirt is 35

Pages: 



 
  Sponsors