Self-taught PHP: String Functions Quick Start
Posted by adminJul 27
Self-taught PHP – String functions Quick Start
by Bill Hamilton
A guy on the fly, programmers watch a first unknown lanquage need a reference of all necessary and most often used functions. This tutorial gives a quick overview of the most important chain Condensed notes followed, then a very short list of operators in PHP and process control.
Functionssubstr (S $, start, length) of the chain from start lengthstrstr S ($ S $ lookfor) part of the string s to lookfor string strstr ($ S $ lookfor, True) last part of the string S, starting lookforstrrchr String ($ S $ lookfor) last part of the string S, starting with the last character lookforstrpos ($ S $ lookfor) first string position in lookfor string strrpos S ($ lookfor) last position of the string lookfor string Sstrlen (S $) length of string (ASCII) ASCII codesubstr_replace (S $, $ R, S, L indicated) Schr Put in $ RS $, from the position s (length L str_replace optional) ($ F, R $, $ s) and replace string in S $ F, replaced by RTRIM $ (S $) Strip whitespace from the end and beginning of $ S (LTRIM and RTRIM too) S. $ $ T concantentate strings instead of strings on $ T $ Secho end of “world” Hello, writes: “Hello world”
Here are some examples of the translation of Visual Basic programmers: Basic PHP ReturnsRight (“abcde”, 3) substr (“abcde”, -3) are “cde” left (“abcde”, 3) substr (“abcde” , 0.3) “abc” mid (“abcde”, 3,2) substr (“abcde”, 2,2) “cd” (count starts at 0) len (“abcde”) strlen (“abcde”) 5replace (“ABCD”, “BC”, “XY”) str_replace (“BC”, “XY”, “abcd”) “aYXd” InStr (“ABCD”, “c”) strpos (“ABCD”, “c” ) 2 (starts to escape 0) chr (27) chr (27) characterltrim (“abc”) LTRIM (“abc”) “abc”
These are the basic string functions you expect from a scripting language lanquage – Search a string and part of a chain breakage and replace on a string. All indices are zero-based chain (the first character position 0). A handy feature is important to note that the starting positions can be negative, you’re the end of the chain and does not count as a start. The last required function is the combination of channels, which is in PHP, all operator time.
Process Control
It implements a very simple series of statements of process control to behave in the usual manner. They are familiar with the investigation if, while, for loop, Case-block (switch), the foreach loop, and continue and break.
The syntax is a little different. Where I (code) means for each line or lines of PHP code, including braces. Each line must end with a semicolon. The parentheses group the lines into one. For example, the code () after the if statement or while statement can be either a single line with a semicolon without parentheses, or one or more rows of staples. The continue command, which skips the rest of the current iteration, has an additional function: add a number to skip the rest of the nested loops. For example, two skips over the current iteration of a loop, and also attached the current loop.
execute if ($ a == “value”) (code) if the return code in brackets. === Using three, is to test Boolean values
while ($ a == “value”) (code), while the loop to run the code in brackets
for ($ i = 1, $ i switch ($ i) (statement of case, as a series of “if” statements of case 0: (code) if $ i == 0, you will break this code works, except you need “break” or it will continue to execute the next lines. Case 1: (code) by default (code) continue), jumps at the end of the current loop (including a switch statement)
foreach ($ a as $ v) code () if $ a $ is an array, the array passes through V for each value assigned to $ value V at each iteration
foreach ($ A as $ key => $ v) if you need to access the array element and not just the value (code) $ key variable for an array element $ V $ is value
include “scriptfilename adding that” the contents of a file in a code
Arithmetic, Boolean and logical operators are exactly as expected, and listed below to complete this reference:
Arithmetic-negative amount of $ a $ a + b $ $ $ a * b add, multiply $ a / $ b divide (float values if the two integers) $ a% $ b & & remainderOperators bitwise logical AND and is & | | logical OR bitwise or |! Logical NOT ~ xor binary not logical XOR bitwise XOR ^
Bill Hamilton is a former database administrator for the United News & Media, Inc. and VNU. It currently operates several PHP / MySQL engine, including web sites www. mysticgemcreations. com
Related posts:

No comments