PHP 8.1.2 Released!


(PHP 4, PHP 5, PHP 7, PHP 8)

printBir dizge çıktılar


print(string $ifade): int

ifadeyi çıktılar.

print aslında bir işlev değildir (bir dil oluşumudur), dolayısıyla değiştirgesini belirtirken yaylı ayraçları kullanmanız gerekmez.

echo'dan başlıca farklar, print'in tek bir değiştirge kabul etmesi ve daima 1 döndürmesidir.



Çıktılanacak ifade. Dizge olmayan değerler strict_types yönergesi etkin olsa bile dizgeye zorlanır.

Dönen Değerler

Daima 1 döner.


Örnek 1 - print örnekleri

print "print yaylı ayraçlar olmadan da çalışır.";

// Satırsonu veya boşluk eklemek gerekmez;
// aşağıdaki tek satırda "helloworld" çıktılar.
+print "hello";

"Bu çok satırlı bir
dizge olup satırsonu karakterleri
de çıktılanır."

"Bu çok satırlı bir\ndizge olup satırsonu karakterleri\nde çıktılanır.";

"Karakterlerin öncelenmesi böyle yapılır: \"Tıpkı böyle\".";

// Değiştirge dizge üreten harhangi bir ifade olabilir
$bu "Bu da";
"$bu Buda"// Bu da Buda

// Ayrıca dizileri de kullanabilirsiniz
$bar = array("değer" => "Buda");

"Bu da {$bar['değer']} !"//  Bu da Buda !

// declare(strict_types=1) olsa bile dizge olmayan iadeler dizgeye zorlanır
print 7// 42

// Tek tırnak içine alırsanız değişken basılır, değeri değil
print '$bu Buda'// $bu Buda

// Başka karakter kullanmazsanız sadece değişkenin değeri basılır
print $bu;          // Bu da

// print değer döndürdüğünden ifadelerde kullanılabilir
// Çıktısı: "hello world"
if ( print "hello" ) {
" world";

// Çıktısı: "true"
=== ) ? print 'true' : print 'false';


Bilginize: Yaylı ayraçların kullanımı

print deyiminin değiştirgesini yaylı ayraçlar arasına almak bir sözdizimi hatasına yol açmaz ve normal bir işlev çağrısı gibi görünen bir sözdizimi de üretmez. Ancak bu yanlış anlaşılabilir, çünkü yaylı ayraçlar aslında çıktılanacak ifadenin parçasıdır, print deyimim parçası değildir.

print "hello";
// "hello" basar

// bu da "hello" basar, çünkü ("hello") geçerli bir ifadedir

print(2) * 3;
// "9" basar; yaylı ayraçlar sayesinde 1+2 önce yorumlanır, sonra da 3*3
// print deyimi ifadenin tümünü tek bir değiştirge olarak görür

if ( print("hello") && false ) {
" - inside if";
else {
" - inside else";
// " - inside if" basar
// ("hello") && false ifadesi önce yorumlanır ve false ile sonuçlanır
// bu boş dizgeye zorlanır "" ve çıktılanır
// print deyimi 1 döndürür, böylece if bloğundaki kod çalıştırılır

print büyük bir ifade ile kullanılırken, anahtar sözcüğü ve değiştirgesini yaylı ayraçlar arasına almak istenen sonucu üretmek için gerekli olabilir:

if ( (print "hello") && false ) {
" - inside if";
else {
" - inside else";
// "hello - inside else" basar
// önceki örneğin tersine (print "hello") ifadesi önce yorumlanır
// "hello" bastıktan sonra 1 döndürür
// 1 && false ifadesinin sonucu false olduğundan else bloğundaki kod çalıştırılır

print "hello " && print "world";
// "world1" basar; önce print "world" yorumanır,
// sonra soldaki print'e "hello " && 1 aktarılır

(print "hello ") && (print "world");
// "hello world" basar; ayraçlar print ifadelerinin
// &&'den önce yorumlanmasını sağlar

Bilginize: Bu bir işlev değil, dil oluşumu olduğundan değişken işlevler kullanılarak çağrılamaz.

Ayrıca Bakınız

add a note add a note

User Contributed Notes 9 notes

user at example dot net
13 years ago
Be careful when using print. Since print is a language construct and not a function, the parentheses around the argument is not required.
In fact, using parentheses can cause confusion with the syntax of a function and SHOULD be omited.

Most would expect the following behavior:
if (print("foo") && print("bar")) {
// "foo" and "bar" had been printed

But since the parenthesis around the argument are not required, they are interpretet as part of the argument.
This means that the argument of the first print is

    ("foo") && print("bar")

and the argument of the second print is just


For the expected behavior of the first example, you need to write:
if ((print "foo") && (print "bar")) {
// "foo" and "bar" had been printed
danielxmorris @ gmail dotcom
13 years ago
I wrote a println function that determines whether a \n or a <br /> should be appended to the line depending on whether it's being executed in a shell or a browser window.  People have probably thought of this before but I thought I'd post it anyway - it may help a couple of people.

function println ($string_message) {
$_SERVER['SERVER_PROTOCOL'] ? print "$string_message<br />" : print "$string_message\n";


Running in a browser:

<?php println ("Hello, world!"); ?>
Output: Hello, world!<br />

Running in a shell:

<?php println ("Hello, world!"); ?>
Output: Hello, world!\n
14 years ago
the FAQTs article can be found archived at

(url split to get past the line-length limitation)
Chris Watson
12 years ago
mvpetrovich of 2007 could just use single quotes as his string delimiters (see the example in the current documentation).
It's not ALWAYS appropriate, but generally it is best (the Zend Framework coding standards have a good take on this). It yields a number of interesting benefits:
1: Nobody will be tempted to write functions to replace backticks or other characters with double quotes. Such functions may cause a (negligible) loss of efficiency, and maybe other undesired effects.
2: You will be able to use double quotes without escaping. This is recommended (although not required) for HTML and XML attributes, as well as quoted text.
3: The script will hit the browser very slightly slightly faster since PHP doesn't have to scan through the string looking for variables, escaped characters, curly braces or other things.
4: Your code gets ten times easier to read. (as mvpetrovich pointed out)

If, in spite of these four excellent benefits, you really MUST still use double quotes to delimit boring old string constants (and seriously, why would you?), you could use the slightly less favourable single quotes as delimiters for most markup languages.
HTML served as HTML will even let you lay out unquoted attributes (yuck).

It should also be noted though that if you are just printing bare strings, you may as well shut off the php parser. The quickest way to send a string is to write it as plain text, OUTSIDE of the php tags. This will also make your code look excellent in a lot of syntax highlighters.

There are few disadvantages to doing this, if any. Output buffering still works. All your classes and objects and includes remain in place. Your script runs faster. World peace is obtained.
jon at tap dot net
16 years ago
I have a small utility run from the command line that processes a potentially huge list of files. As it can take hours to complete, I stuck a 

print '.';

statement in the body of the main loop to prove that something was  happening.

For reasons unknown to me, the utiliity suddenly started buffering the output such that it printed nothing until completion, defeating the purpose of the running monitor. Adding flush() statements did nothing. The problem was solved by using

fputs(STDOUT, '.');

but I have no idea why.
3 years ago
Don't rely on parenthesis used for `print` construct:

print 1 . print(2) + 3;
print PHP_EOL;
print 1 . (print(2)) + 3;
phpnet at i3x171um dot com
15 years ago
I have written a script to benchmark the several methods of outputting data in PHP: via single quotes, double quotes, heredoc, and printf. The script constructs a paragraph of text with each method. It performs this construction 10,000 times, then records how long it took. In total, it prints 160,000 times and records 16 timings. Here are the raw results.

Outputted straight to browser--

Single quotes: 2,813 ms
...with concatenation: 1,179 ms
Double quotes: 5,180 ms
...with concatenation: 3,937 ms
heredoc: 7,300 ms
...with concatenation: 6,288 ms
printf: 9,527 ms
...with concatenation: 8,564 ms

Outputted to the output buffer--

Single quotes: 8 ms
...with concatenation: 38 ms
Double quotes: 8 ms
...with concatenation: 47 ms
heredoc: 17 ms
...with concatenation: 49 ms
printf: 54 ms
...with concatenation: 52 ms

A nice graph of the script's output can be found here:

So what should you choose to print your text? I found several things out writing this.

First, it should be noted that the print and echo keywords are interchangeable, performance-wise. The timings show that one is probably an alias for the other. So use whichever you feel most comfortable with.

Second, if you've ever wondered which was better, the definitive answer is single quotes. Single quotes are at least four times faster in any situation. Double quotes, while more convenient, do pose a debatably significant performance issue when outputting massive amounts of data.

Third, stay away from heredoc, and absolutely stay away from [s]printf. They're slow, and the alternatives are there.

The source of my script can be found here:

DO NOT RUN THE SCRIPT ON THE INTERNET! Run it instead from localhost. The script outputs ~45 megabytes of text in an html comment at the top of the page by default. Expect the benchmark to take ~45 seconds. If this is too long, you can change the amount of iterations to a lower number (the results scale accurately down to about 1,000 iterations).
ejallison at gmail dot com
16 years ago
This is a simple function for printing debug comments that I didn't think of for a long time. Maybe it'll serve you good too.


function printd($str) {
  if (
$debug) { echo $str; }

// ...

if ($valueCalculatedEarlierInTheScript == 3) {
printd("doSomethingWithNoOutput() has executed.");


It's mostly just to make sure everything is running without having to go through everything and put in echo "Step #whatever has executed" whenever something mysterious isn't working.
13 years ago
An update to the println function I wrote below, this is a more efficient, correct and returns a value (1, always; (print)).


function println($string_message = '') {
        return isset(
$_SERVER['SERVER_PROTOCOL']) ? print "$string_message<br />" . PHP_EOL:
$string_message . PHP_EOL;

To Top