Home arrow PHP arrow Page 4 - Programming PHP: A Beginner`s Guide

Working with Strings - PHP

PHP has been taking the web by storm because of its power and versatility. If you'd like to add PHP-based applications to your web site, keep reading. This series of articles will teach you the language from scratch.

TABLE OF CONTENTS:
  1. Programming PHP: A Beginner`s Guide
  2. PHP Means PHP: Hypertext Preprocessor
  3. Variables
  4. Working with Strings
By: James Payne
Rating: starstarstarstarstar / 19
October 29, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Now that we know how to print a string and create variables to hold strings, let's look at some ways to manipulate strings.


<html>

<body>


<?php

$first_name = "James";

$last_name = "Payne";


echo $first_name . " " . $last_name; concatenation

?>


</body>

</html>

The above code is called concatenation and is used to join two things together (in this case, two words). The above code prints out the text:

  James Payne

You will note the " " places a space between the words.

There are a ton of functions that let you goof around with strings in PHP, and I will write a tutorial on them in the near future.

In addition to toying with strings, you can also manipulate numeric data as well. To do this we use operators. Below is a giant list of the different operators available to you in PHP.

 

Symbol

What it Does

Type

+

Used for Addition

Arithmetic

-

Used for Subtraction

Arithmetic

*

Used for Multiplication

Arithmetic

/

Used for Dividing

Arithmetic

%

Used for Modulation

Arithmetic

++

Used to increase value by one

Arithmetic

--

Used to decrease value by one

Arithmetic

"="

Used to Assign a Value

Comparison

+=

Used to Add and Assign a Value

Comparison

-=

Used to Subtract and Assign a Value

Comparison

*=

Used to Multiply and Assign a Value

Comparison

/=

Used to Divide and Assign a Value

Comparison

.=

Decimals and Adds a Value

Comparison

%=

Used to Modulate and Add a Value

Comparison

"=="

Equal To

Comparison

!=

Not Equal To

Comparison

>

Greater Than

Comparison

<

Less Than

Comparison

>=

Greater Than or Equal To

Comparison

<=

Less Than or Equal To

Comparison

&&

Checks for more than one criteria

Logical

||

Checks to see if at least one of a set of criteria is true

Logical

!

Checks to see if a criteria is not true

Logical

Well that's all the time we have for this tutorial. In our next episode, we will discuss how to use the various operators to further manipulate our data. If we have time we discuss Conditional Statements as well.

Till then...



 
 
>>> More PHP Articles          >>> More By James Payne
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap

Dev Shed Tutorial Topics: