Description
The print of String for PHP print is a language construct, not a function, so parentheses are not required..
Syntax
print( string $expression ): int
Parameters
expression
The expression to be output. Non-string values will be coerced to strings, even when the strict_types directive is enabled.
Return
Returns 1, always.
Examples
1 · with parentheses
<? $expression = "with ()"; print($expression); ?>
with ()
2 · without parentheses
<? $expression = "without ()"; print $expression; ?>
without ()
3 · multiple lines
<? $expression = "multiple lines"; print $expression; ?>
multiple lines
4 · newline character
<? $expression = "newline\ncharacter"; print $expression; ?>
newline character
5 · escape character
<? $expression = "escape characters \"like this\""; print $expression; ?>
escape characters "like this"
6 · double quotes
<? $var = "variable"; $expression = "variables are expanded inside double quotes: $var"; print $expression; ?>
variables are expanded inside double quotes: variable
7 · single quotes
<? $var = "variable"; $expression = 'variables are not expanded inside single quotes: $var'; print $expression; ?>
variables are not expanded inside single quotes: $var
8 · curly braces
<? $array = array("key" => "value"); $expression = "array: {$array['key']}"; print $expression; ?>
array: value
9 · concatenation
<? $expression1 = 'concatenation, '; $expression2 = 'passed '; $expression3 = 'together'; print $expression1 . $expression2 . $expression3 . PHP_EOL . PHP_EOL; function myfunction($myparameter) { var_export('function'); return $myparameter; } print myfunction(1) . myfunction(2) . myfunction(3); ?>
concatenation, passed together 'function''function''function'123
10 · heredoc
<? $var = "variable"; print <<<MYIDENTIFIER The heredoc allows output on multiple lines. Syntax begins with <<< and an identifier. Variables are expanded: $var. Syntax ends with an identifier whose placement determines the indentation. MYIDENTIFIER; ?>
The heredoc allows output on multiple lines. Syntax begins with <<< and an identifier. Variables are expanded: variable. Syntax ends with an identifier whose placement determines the indentation.
11 · nowdoc
<? $var = "variable"; print <<<'MYIDENTIFIER' The nowdoc allows output on multiple lines. Syntax begins with <<< and an identifier in single quotes. Variables are not expanded: $var. Syntax ends with an identifier whose placement determines the indentation. MYIDENTIFIER; ?>
The nowdoc allows output on multiple lines. Syntax begins with <<< and an identifier in single quotes. Variables are not expanded: $var. Syntax ends with an identifier whose placement determines the indentation.
12 · an expression
<? $expression = 'expression'; // valid ($expression) ? print 'true' : print 'false'; // valid print $expression ? 'true' : 'false'; ?>
truetrue
Links
Related
String
- addcslashes
- addslashes
- bin2hex
- chop
- chr
- chunk_split
- convert_uudecode
- convert_uuencode
- count_chars
- crc32
- crypt
- echo
- explode
- fprintf
- get_html_translation_table
- hebrev
- hebrevc
- hex2bin
- html_entity_decode
- htmlentities
- htmlspecialchars
- htmlspecialchars_decode
- implode
- join
- lcfirst
- levenshtein
- localeconv
- ltrim
- md5
- md5_file
- metaphone
- nl_langinfo
- nl2br
- number_format
- ord
- parse_str
- printf
- quoted_printable_decode
- quoted_printable_encode
- quotemeta
- rtrim
- setlocale
- sha1
- sha1_file
- similar_text
- soundex
- sprintf
- sscanf
- str_contains
- str_decrement
- str_ends_with
- str_getcsv
- str_increment
- str_ireplace
- str_pad
- str_repeat
- str_replace
- str_rot13
- str_shuffle
- str_split
- str_starts_with
- str_word_count
- strcasecmp
- strchr
- strcmp
- strcoll
- strcspn
- strip_tags
- stripcslashes
- stripos
- stripslashes
- stristr
- strlen
- strnatcasecmp
- strnatcmp
- strncasecmp
- strncmp
- strpbrk
- strpos
- strrchr
- strrev
- strripos
- strrpos
- strspn
- strstr
- strtok
- strtolower
- strtoupper
- strtr
- substr
- substr_compare
- substr_count
- substr_replace
- trim
- ucfirst
- ucwords
- vfprintf
- vprintf
- vsprintf
- wordwrap