Creating and Accessing Strings
- Single Quotation String
$mystring= 'This is Single Quotation String';
- Double Quotation String
$mystring= "This is Double Quotation String";
Single and double quotation marks work in diffrent ways. If you enclose a string is in single quotation marks, PHP use the string exactly as typed. However, double quotaion marks give you a couple of extra features.
- Any variable names within the string are parsed and replaced with the variables value.
- You can include specail characters in the string by escaping them.
Here are some example to make these difference clear:
<?php $a='SOFTAID'; $b="PHP is a server side scripting language"; $br="<br/>";// for breacking line echo "Hello, $a! <br/>"; echo 'Hello, $b!<br/>'; ?>
PHP String Functions
PHP gives you several string functions that let you:
chr(): Returns a character from a specified ASCII value.
<?php $br="<br/>"; echo $br.chr(65); echo $br.chr(97); ?>
chop(): Removes whitespace or other character from the right end other a string.
<?php $br="<br/>"; $str="SOFTAID INFOWEB"; echo chop($str,"WEB"); echo $br.$str; ?>