{"id":9948,"date":"2020-02-04T09:44:23","date_gmt":"2020-02-04T09:44:23","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=9948"},"modified":"2021-11-13T05:44:05","modified_gmt":"2021-11-13T05:44:05","slug":"echo-statement-print-statement-and-here-document-in-php","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/echo-statement-print-statement-and-here-document-in-php\/","title":{"rendered":"Echo Statement, Print Statement, and Here document in PHP."},"content":{"rendered":"\n<h1 class=\"has-text-align-center wp-block-heading\"><em>Echo Statement<\/em><\/h1>\n\n\n\n<p><em>This statement is used to output the data to the screen or printing text on the screen. For Example:- <br>echo &#8220;Sushant Kumar&#8221;;<br>echo &#8216;Sushant Kumar&#8217;;<br>echo 59.236;<br>echo (&#8220;Sushant Kumar&#8221;);<br>echo &#8220;Sushant&#8221; , &#8220;Kumar&#8221;;<br>echo &#8220;Sushant&#8221; . &#8220;Kumar&#8221;;<\/em><\/p>\n\n\n\n<p>Note- We use both (,) and (.) for concate.<\/p>\n\n\n\n<h2 class=\"has-text-align-center wp-block-heading\"><em>echo with HTML<\/em><\/h2>\n\n\n\n<p>You can use HTML tags with echo statement and tags should be written under double quote(&#8220;Example&#8221;). <strong>For Example:-<\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/1c63dfcb0d20af14803ce299b9d34f15.js\"><\/script>\n\n\n\n<p><strong><em>Output:<\/em><\/strong>      <strong>Sushant Kumar<\/strong><\/p>\n\n\n\n<h2 class=\"has-text-align-center wp-block-heading\"><strong><em>echo with Variable<\/em><\/strong><\/h2>\n\n\n\n<p>You can also use echo with a variable to print the value of the variable. <strong>For Example:- <\/strong><br> <em>$value1 = 10<\/em><br> to print the value of variable <em>value1<\/em> we write, <br> <em>echo $value1;<\/em><\/p>\n\n\n\n<p> then, it prints the value,   <\/p>\n\n\n\n<p><strong>Output:- <\/strong>10<\/p>\n\n\n\n<p>We can also display both text and variable value at once, see below<br>Here Variable is <\/p>\n\n\n\n<p><em>$name = &#8220;Sushant&#8221;;<\/em><br><em>echo &#8220;I am &#8221; , $name;<\/em><\/p>\n\n\n\n<p><strong>Output:<\/strong>       <em>I am Sushant<\/em><\/p>\n\n\n\n<p>If you want to use HTML tags in Variable then, see the below example<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/fd54f716c5aad43a024303cf0a8d05b2.js\"><\/script>\n\n\n\n<p> It Display&#8217;s name in Bold, <\/p>\n\n\n\n<p><strong>Output:-<\/strong>     <strong>Sushant<\/strong><\/p>\n\n\n\n<p><strong>Note:-<\/strong> 1. The text should be enclosed with quotes.                                                                                                    2. HTML tags should be enclosed with quotes.<\/p>\n\n\n\n<h1 class=\"has-text-align-center wp-block-heading\"><strong><em>Print Statement<\/em><\/strong><\/h1>\n\n\n\n<p>This is very similar to the echo statement, a way of displaying text. <strong>For Example:- <\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/6dc5768e35274bd89648081e4f0b6b23.js\"><\/script>\n\n\n\n<p><strong>Output:<\/strong> Sushant Kumar<\/p>\n\n\n\n<p>Similarly, if you want to display text and variable both, then see the below example:- <\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/eba75e80abd1ee0a04dccfa0d8c3f45f.js\"><\/script>\n\n\n\n<p><strong>Output:<\/strong> Hello, I am Sushant Kumar<\/p>\n\n\n\n<h3 class=\"has-text-align-center wp-block-heading\"><em><strong>Difference Between print and echo.<\/strong><\/em><\/h3>\n\n\n\n<ol class=\"wp-block-list\"><li>echo has no return value while print is more like PHP function so it returns a value, which is always set to 1.<\/li><li>echo can take multiple parameters while print can take only one.<\/li><li>echo is marginally faster than print.<\/li><\/ol>\n\n\n\n<h1 class=\"has-text-align-center wp-block-heading\"><em><strong>Here document in PHP<\/strong><\/em> <\/h1>\n\n\n\n<p>PHP here document is another way of displaying text. a here document(heredoc) is just some text inserted directly in a PHP page. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><em>Syntax:- <\/em><\/strong><\/h3>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/0d7d470146a8370e735eccb6deac970a.js\"><\/script>\n\n\n\n<p><strong>For Example:- <\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/8e65e4a08f3822b4ec68351dbeab82cd.js\"><\/script>\n\n\n\n<p><strong>Output:- <\/strong><br> Hello<br> I am sushant kumar<br> I am A boy<\/p>\n\n\n\n<p> Click Here For Next Part \u2013&nbsp;<a href=\"https:\/\/www.devopsschool.com\/blog\/what-are-comments-constant-variable-string-interpolation-arithmetic-and-assignment-operators-in-php\/\">What are Comments, Constant Variable, String Interpolation, Arithmetic and Assignment Operators in PHP?<\/a><\/p>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_68535\"><iframe loading=\"lazy\"  id=\"_ytid_64193\"  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_68535\"  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>Echo Statement This statement is used to output the data to the screen or printing text on the screen. For Example:- echo &#8220;Sushant Kumar&#8221;;echo &#8216;Sushant Kumar&#8217;;echo 59.236;echo (&#8220;Sushant Kumar&#8221;);echo &#8220;Sushant&#8221;&#8230; <\/p>\n","protected":false},"author":19,"featured_media":10843,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5150],"tags":[5868,5869,5870,5872,5873,177,5858,5867,5871,5859],"class_list":["post-9948","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-echo-statement","tag-echo-with-html","tag-echo-with-variable","tag-here-document-in-php","tag-html-tags","tag-php","tag-php-tutorial","tag-php-tutorial-2020","tag-print-statement","tag-tutorial-for-beginners"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/9948","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\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=9948"}],"version-history":[{"count":58,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/9948\/revisions"}],"predecessor-version":[{"id":24973,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/9948\/revisions\/24973"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/10843"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=9948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=9948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=9948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}