{"id":15183,"date":"2020-06-19T18:04:45","date_gmt":"2020-06-19T18:04:45","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=15183"},"modified":"2022-04-28T09:15:24","modified_gmt":"2022-04-28T09:15:24","slug":"echo-and-print-statements-in-php","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/echo-and-print-statements-in-php\/","title":{"rendered":"Echo And Print Statements In PHP"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">What is echo in PHP<\/h4>\n\n\n\n<p>This statement is used to output the data to the screen or printing text on screen.<\/p>\n\n\n\n<p>The echo statement can output one or more strings. In general terms, the echo statement can display anything that can be displayed to the browser, such as string, numbers, variables values, the results of expressions, etc.<\/p>\n\n\n\n<p>Since echo is a language construct not actually a function (like&nbsp;if&nbsp;a statement), you can use it without parentheses e.g.&nbsp;<code>echo<\/code>&nbsp;or&nbsp;<code>echo()<\/code>. However, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/8450c571fc6ea4360cf743adbcdf4373.js\"><\/script>\n\n\n\n<p>The output of the above PHP code will look something like this: Devopsschool!<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">echo with HTML<\/h4>\n\n\n\n<p>The following example will show you how to display HTML code using the echo statement:<\/p>\n\n\n\n<p><strong>Example<\/strong>:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/aecd1ec5956db424565afcdc4c5c2b62.js\"><\/script>\n\n\n\n<p>The output of the above PHP code will look something like this:<\/p>\n\n\n\n<p>This is a simple heading.<\/p>\n\n\n\n<p><span style=\"color:#e70808\" class=\"has-inline-color\">This is heading with style.<\/span><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Display Variables<\/h4>\n\n\n\n<p>The following example will show you how to display variable using the echo statement:<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/d9f0da483029960226336a15d3eae1f3.js\"><\/script>\n\n\n\n<p>The output of the above PHP code will look something like this:<\/p>\n\n\n\n<p>Hello Dharmu!<br>150696<br>Red<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is print in PHP<\/h3>\n\n\n\n<p>You can also use the print statement (an alternative to&nbsp;<code>echo<\/code>) to display output to the browser. Like echo the print is also a language construct not a real function. So you can also use it without parentheses like:&nbsp;<code>print<\/code>&nbsp;or&nbsp;<code>print()<\/code>.<\/p>\n\n\n\n<p>Both&nbsp;<code>echo<\/code>&nbsp;and&nbsp;<code>print<\/code>&nbsp;statement works exactly the same way except that the&nbsp;<code>print<\/code>&nbsp;statement can only output one string, and always returns 1. That&#8217;s why the&nbsp;<code>echo<\/code>&nbsp;statement considered marginally faster than the&nbsp;<code>print<\/code>&nbsp;statement since it doesn&#8217;t return any value.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">print with HTML<\/h3>\n\n\n\n<p>The following example will show you how to display HTML code using the print statement:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/2fd92536dbe5dce7737a718f06fac209.js\"><\/script>\n\n\n\n<p>The output of the above PHP code will look something like this:<\/p>\n\n\n\n<p>This is a simple heading.<\/p>\n\n\n\n<p><span style=\"color:#d12e31\" class=\"has-inline-color\">This is heading with style.<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Display Variables<\/h3>\n\n\n\n<p>The following example will show you how to display variable using the print statement:<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/db86b269751e1482d2276f73083dfff3.js\"><\/script>\n\n\n\n<p>The output of the above PHP code will look something like this:<\/p>\n\n\n\n<p>Hello Dharmu!<br>123456789<br>Red<\/p>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_67428\"><iframe loading=\"lazy\"  id=\"_ytid_74279\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_67428\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>What is echo in PHP This statement is used to output the data to the screen or printing text on screen. The echo statement can output one or more strings&#8230;. <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5150],"tags":[6151,6150,5869,6152,6153],"class_list":["post-15183","post","type-post","status-publish","format-standard","hentry","category-php","tag-display-variables","tag-echo-in-php","tag-echo-with-html","tag-print-in-php","tag-print-with-html"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/15183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=15183"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/15183\/revisions"}],"predecessor-version":[{"id":24745,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/15183\/revisions\/24745"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=15183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=15183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=15183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}