Changes

Jump to: navigation, search

Understanding PHP Variable Types

689 bytes added, 20:05, 25 May 2007
The PHP String Variable
<?php
$myString = "A string of text";
$myString2 = 'Another string of text';
$myString3 = "This string contains 'single quotes'";
$myString4 = 'This string contains "double quotes"';
?>
<?php
$myString3 = 'This string contains \'single quotes\'';
$myString4 = "This string contains \"double quotes\" and \'single quotes\'";
?>
<td>\"<td>Double quotation mark</td>
<tr>
<td>\$<td>Dollar sign (prevent prevents text from being treated as a variable name)</td>
<tr>
<td>\034<td>Octal ASCII value</td>
<?php
$myString = "This is a line of Text\nandthis is another line with a tab here \t for us.";
?>
</pre>
 
== Extracting and Writing String Fragments ==
 
 
 
== Creating PHP heredoc Strings ==
 
The PHP ''heredoc'' string syntax allows ''free form'' text to be used without having to worry about 'escaping'' special characters such as quotes and backslashes. The content of the heredoc string is wrapped with ''<<<EOD'' and ''EOD;'' markers.
 
The only rules are that the closing ''EOD;'' must be at the ''beginning'' of the last line, and the ''only'' content on that line, as follows:
 
<pre>
<?php
 
$myString = <<<EOD
This is some free form text. It can span mutliple
lines and can contain otherwise troublesome characters like
\ and " and ' without causing any problems.
EOD;
 
?>
</pre>
== Converting Between PHP Strings, Numbers and Floats ==

Navigation menu