Now that you know how to create strings in PHP, it’s time to try out some basic string operations. In this tutorial you learn how to:
- Join strings together
- Find out the length of a string, and
- Read and change individual characters within a string.
Matt Doyle | Elated Communications
Web and WordPress Development
Explore PHP, one of the most popular Web programming languages in use today. Learn how PHP works and how to write useful PHP scripts and applications.
See also:Now that you know how to create strings in PHP, it’s time to try out some basic string operations. In this tutorial you learn how to:
A string in PHP is any sequence of characters. Here are some examples of strings:
Hello, world!
abc123
#@@$%&*%
PHP lets you work with strings in many different ways. For example, you can search a string for a piece of text; extract characters from a string; and format a string to make it easier to read or use.
In this tutorial you learn how to create strings in your PHP scripts. You look at:
PHP loops allow you to run the same chunk of code repeatedly. PHP features while
and do...while
loops, which are handy for general-purpose looping, and the more specialized for
loop, which is useful when you want to run a chunk of code a known number of times.
This article explains how PHP for
loops work, and shows you some practical for
loop examples.
PHP loops let you run a block of PHP code over and over again. They’re great for repetitive tasks such as reading data records from a database, or displaying rows of a table in a Web page.
The PHP while
loop is the simplest type of loop to understand. In this article you look at the syntax of a PHP while
loop, and explore some example loops. You also look at do...while
loops.
The PHP if
and else
statements let a script decide whether to run a chunk of code based on a condition. The if
statement runs a chunk of code if the condition is true or skips it if the condition is false. if
combined with else
runs one chunk if the condition is true, or the other chunk if the condition is false.
PHP lets you take things further, and chain several decision-making blocks together, with each block having its own condition to test. To do this, you use the elseif
statement.
The PHP if
statement lets a script test to see if a certain condition is true, and run a chunk of code if it is. This allows your code to make decisions about what to do next, thereby adding a lot of power to your scripts.
[Read more…] about Making Decisions with the PHP if Statement
Like most languages, PHP lets you add comments to your code. Comments are chunks of text that are ignored when the code is run by the PHP engine, but which are useful to programmers who need to read the code.
In this article you learn how to create PHP comments, and look at some good commenting practices, including how to write and format comments effectively. You also find out how to use comments to “comment out” chunks of PHP code.
Most PHP scripts deal with data in one form or another, usually stored in variables. PHP can work with different types of data. For example, a whole number is said to have an integer data type, while a string of text has a string data type.
In this article you explore PHP’s data types; look at loose typing; learn how to discover the type of a given value; and see how to change data types.
PHP variables are great for storing values in your script, but they’re not much use on their own. To manipulate variable values and get useful results, you need to use operators.
You might be familiar with using PHP variables to store values in PHP scripts. PHP constants are similar, but have a few important differences, as you’ll see in this article.
Copyright © 1996-2023 Elated Communications. All rights reserved.
Affiliate Disclaimer | Privacy Policy | Terms of Use | Service T&C | Credits