INSERT INTO "table1" ("column1", "column2", ...) SELECT "column3", "column4", ... FROM "table2" INSERT INTO Store_Information (store_name, Sales, Date) SELECT store_name, Sales, Date FROM Sales_Information WHERE Year(Date) = 1998
Author: Melvin
Using substr()
<?php
print substr(‘abcdef’, 1); // bcdef
print substr(‘abcdef’, 1, 3); // bcd
print substr(‘abcdef’, 0, 4); // abcd
print substr(‘abcdef’, 0, 8 ); // abcdef
print substr(‘abcdef’, -1, 1); // f// Accessing single characters in a string
// can also be achived using “curly braces”
$string = ‘abcdef’;
print $string{0}; // a
print $string{3}; // d
print $string{strlen($string)-1}; // f?>
Negative start
<?php
$test_var = substr(“abcdef”, -1); // returns “f”
$test_var = substr(“abcdef”, -2); // returns “ef”
$test_var = substr(“abcdef”, -3, 1); // returns “d”
?>
String Functions (Len, Left, Right, Mid)
<% dim myvar myvar = "1234567" response.Write(myvar & " is the variable<br/>")
response.Write(len(myvar) & " characters long<br/>")
response.Write(left(myvar,3) & " are the <b>left</b> three characters<br/>")
response.Write(right(myvar,3) & " are the <b>right</b> three characters<br/>")
response.Write(mid(myvar,3,3) & " : Mid(MyString, StartPos, NumChars)<br/> %>
Output:
1234567 is the variable
7 characters long
123 are the left three characters
567 are the right three characters
345 : Mid(MyString, StartPos, NumChars)
ASP: Find the length of a string using len and lenB function
my_string="Welcome to MySite.com" Response.Write ( my_string ) Response.Write "Length of this string = " & len(my_string) Response.Write "Number of bytes Required for this string = " & lenB(my_string)
The output of this will also show the number of bytes required. Here in this case it will print this:
Welcome to MySite.com
Length of this string = 21
Number of bytes Required for this string = 42
PHP: Expressions and Operators
Arithmetic Operators:
+ Addition Add two values
– Subtraction Subtract the second value from the first
* Multiplication Multiply two values
/ Division Divide the first value by the second
% Modulus Divide the first value by the second and return only the remainder
(for example, 7 % 5 yields 2)
Comparison Operators:
= = Equal Checks for equal values
= = = Identical Checks for equal values and data types
! = Not Equal Checks for values not equal
! = = Not Identical Checks for values not equal or not the same data type
< Less than Checks for one value being less than the second
> Greater than Checks for one value being greater than the second
< = Less than or Equal to Checks for on value being less than or equal to the second
> = Greater than or Equal to Checks for on value being greater than or equal to the second
Logical Operators:
And Checks if two or more statements are true
&& Same as And
Or Checks if at least one of two statements is true
|| Same as Or
Xor Checks if only one of two statements is true
! Checks if a statement is not true
Increment and Decrement Operators:
++value Pre-Increment Adds 1 to the value before processing the expression which uses the value
–value Pre-Decrement Subtracts 1 from the value before processing the expression which uses the value
value++ Post-Increment Adds 1 to the value after processing the expression which uses the value
value– Post-Decrement Subtracts 1 from the value after processing the expression which uses the value
SQL Select leftmost or rightmost characters from rows of data
SELECT left(item_num, 4) FROM flowers;
If item_num = 754861 then the output will be: 7548
SELECT right(item_num, 4) FROM flowers;
If item_num = 754861 then the output will be: 4861
eregi_replace() vs. ereg_replace()
Code:
<?php
$s = “Coding PHP is fun.”;
print “ereg_replace(): ” .
ereg_replace(“CODING”, “Learning”, $s) . “<br>”;
print “eregi_replace(): ” .
eregi_replace(“CODING”, “Learning”, $s);?>
Output:
ereg_replace(): Coding PHP is fun.
eregi_replace(): Learning PHP is fun.
Explanation:
eregi_replace() is case insensitive, while ereg_replace() is not.
HTML Special Characters
– | – | – | en dash |
— | — | — | em dash |
¡ | ¡ | ¡ | inverted exclamation |
¿ | ¿ | ¿ | inverted question mark |
" | " | " | quotation mark |
“ | “ | “ | left double curly quote |
” | ” | ” | right double curly quote |
' | ' | apostrophe (single quote) | |
‘ | ‘ | ‘ | left single curly quote |
’ | ’ | ’ | right single curly quote |
« » | « » | « » | guillemets |
|   | non-breaking space | |
Symbols | |||
& | & | & | ampersand |
¢ | ¢ | ¢ | cent |
© | © | © | copyright |
÷ | ÷ | ÷ | divide |
> | > | > | greater than |
< | < | < | less than |
µ | µ | µ | micron |
· | · | · | middle dot |
¶ | ¶ | ¶ | pilcrow (paragraph sign) |
± | ± | ± | plus/minus |
€ | € | € | Euro |
£ | £ | £ | British Pound Sterling |
® | ® | ® | registered |
§ | § | § | section |
™ | ™ | ™ | trademark |
¥ | ¥ | ¥ | Japanese Yen |
Diacritics | |||
á Á | á Á | á Á | lower-case "a" with acute accent upper-case "A" with acute accent |
à À | à À | à À | lower-case "a" with grave accent upper-case "A" with grave accent |
â Â | â Â | â Â | lower-case "a" with circumflex upper-case "A" with circumflex |
å Å | å Å | å Å | lower-case "a" with ring upper-case "A" with ring |
ã Ã | ã Ã | ã Ã | lower-case "a" with tilde upper-case "A" with tilde |
ä Ä | ä Ä | ä Ä | lower-case "a" with diaeresis/umlaut upper-case "A" with diaeresis/umlaut |
æ Æ | æ Æ | æ Æ | lower-case "ae" ligature upper-case "AE" ligature |
ç Ç | ç Ç | ç Ç | lower-case "c" with cedilla upper-case "C" with cedilla |
é É | é É | é É | lower-case "e" with acute accent upper-case "E" with acute accent |
è È | è È | è È | lower-case "e" with grave accent upper-case "E" with grave accent |
ê Ê | ê Ê | ê Ê | lower-case "e" with circumflex upper-case "E" with circumflex |
ë Ë | ë Ë | ë Ë | lower-case "e" with diaeresis/umlaut upper-case "E" with diaeresis/umlaut |
í Í | í Í | í Í | lower-case "i" with acute accent upper-case "I" with acute accent |
ì Ì | ì Ì | ì Ì | lower-case "i" with grave accent upper-case "I" with grave accent |
î Î | î Î | î Î | lower-case "i" with circumflex upper-case "I" with circumflex |
ï Ï | ï Ï | ï Ï | lower-case "i" with diaeresis/umlaut upper-case "I" with diaeresis/umlaut |
ñ Ñ | ñ Ñ | ñ Ñ | lower-case "n" with tilde upper-case "N" with tilde |
ó Ó | ó Ó | ó Ó | lower-case "o" with acute accent upper-case "O" with acute accent |
ò Ò | ò Ò | ò Ò | lower-case "o" with grave accent upper-case "O" with grave accent |
ô Ô | ô Ô | ô Ô | lower-case "o" with circumflex upper-case "O" with circumflex |
ø Ø | ø Ø | ø Ø | lower-case "o" with slash upper-case "O" with slash |
õ Õ | õ Õ | õ Õ | lower-case "o" with tilde upper-case "O" with tilde |
ö Ö | ö Ö | ö Ö | lower-case "o" with diaeresis/umlaut upper-case "O" with diaeresis/umlaut |
ß | ß | ß | ess-tsett |
ú Ú | ú Ú | ú Ú | lower-case "u" with acute accent upper-case "U" with acute accent |
ù Ù | ù Ù | ù Ù | lower-case "u" with grave accent upper-case "U" with grave accent |
û Û | û Û | û Û | lower-case "u" with circumflex upper-case "U" with circumflex |
ü Ü | ü Ü | ü Ü | lower-case "u" with diaeresis/umlaut upper-case "U" with diaeresis/umlaut |
ÿ | ÿ | ÿ | lower-case "y" with diaeresis/umlaut |
´ ` | ´ ` | acute accent with no letter grave accent/reversed apostrophe with no letter |
Formatting money / currency using PHP
$formatted = number_format($number,2);
PHP basename() Function
The basename() function returns the filename from a path.
<?php
$path = “/mywebsite/home.php”;
//Show filename with file extension
echo basename($path) .”<br/>”;
//Show filename without file extension
echo basename($path,”.php”);
?>
The output of the code above will be:
home.php
home