PHP: echo - Manual
[/] Downloads Documentation Get Involved Help PHP 7.1.4 Released Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Errors Exceptions Generators References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting Using Register Globals User Submitted Data Magic Quotes Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Safe Mode Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Credit Card Processing Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation GUI Extensions Keyboard Shortcuts ? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search (current page) / Focus search box explode » « crypt PHP Manual Function Reference Text Processing Strings String Functions Change language: English Brazilian Portuguese Chinese (Simplified) French German Japanese Romanian Russian Spanish Turkish Other Edit Report a Bug echo (PHP 4, PHP 5, PHP 7) echo — Output one or more strings Description void echo ( string $arg1 [, string $... ] ) Outputs all parameters. No additional newline is appended. echo is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo , the parameters must not be enclosed within parentheses. echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syntax only works with the short_open_tag configuration setting enabled. I have =$foo?> foo. The major differences to print are that echo accepts an argument list and doesn't have a return value. Parameters arg1 The parameter to output. ... Return Values No value is returned. Examples Example #1 echo examples "foo" ); echo "this is { $baz [ 'value' ]} !" ; // this is foo ! // Using single quotes will print the variable name, not the value echo 'foo is $foo' ; // foo is $foo // If you are not using any other characters, you can just echo variables echo $foo ; // foobar echo $foo , $bar ; // foobarbarbaz // Strings can either be passed individually as multiple arguments or // concatenated together and passed as a single argument echo 'This ' , 'string ' , 'was ' , 'made ' , 'with multiple parameters.' , chr ( 10 ); echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "\n" ; echo <<
Notes Note : Because this is a language construct and not a function, it cannot be called using variable functions . Tip A benefit to passing in multiple arguments over using concatenation in echo regards the precedence of the period operator in PHP. If multiple arguments are passed in, then parentheses will not be required to enforce precedence: Could even be worth getting into the habit of enclosing all variables in {} when writing echo strings, to be on the safe side. up down 1 pemapmodder1970 at gmail dot com ¶ 18 days ago Passing multiple parameters to echo using commas (',')is not exactly identical to using the concatenation operator ('.'). There are two notable differences. First, concatenation operators have much higher precedence. Referring to http://php.net/operators.precedence, there are many operators with lower precedence than concatenation, so it is a good idea to use the multi-argument form instead of passing concatenated strings. Second, a slightly confusing phenomenon is that unlike passing arguments to functions, the values are evaluated one by one. The output would be: string(3) "bar"FoobarFoo Foostring(3) "bar" barFoo It would become a confusing bug for a script that uses blocking functions like sleep() as parameters: vs With ',' the cursor stops at the beginning every newline, while with '.' the cursor stops after the 0 in the beginning every line (because sleep() returns 0). up down -1 214363570 at qq dot com ¶ 22 days ago Dear: Is there a offical function like echoln(), such as function echoln($s=""){ echo $s."\n"; } $str = "i love php"; echoln($str); echoln($str); echoln($str); echoln($str); not is: echo $str."\n"; echo $str."\n"; echo $str."\n"; echo $str."\n"; echo $str."\n"; Thank you. Best regards. add a note String Functions addcslashes addslashes bin2hex chop chr chunk_split convert_cyr_string convert_uudecode convert_uuencode count_chars crc32 crypt echo explode fprintf get_html_translation_table hebrev hebrevc hex2bin html_entity_decode htmlentities htmlspecialchars_decode htmlspecialchars implode join lcfirst levenshtein localeconv ltrim md5_file md5 metaphone money_format nl_langinfo nl2br number_format ord parse_str print printf quoted_printable_decode quoted_printable_encode quotemeta rtrim setlocale sha1_file sha1 similar_text soundex sprintf sscanf str_getcsv str_ireplace str_pad str_repeat str_replace str_rot13 str_shuffle str_split 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_compare substr_count substr_replace substr trim ucfirst ucwords vfprintf vprintf vsprintf wordwrap Copyright © 2001-2017 The PHP Group My PHP.net Contact Other PHP.net sites Mirror sites Privacy policy