{"id":1617,"date":"2015-05-19T05:49:18","date_gmt":"2015-05-19T05:49:18","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=1617"},"modified":"2015-08-03T06:02:20","modified_gmt":"2015-08-03T06:02:20","slug":"how-to-rewrite-php-echo-with","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/stack-overflow\/how-to-rewrite-php-echo-with\/","title":{"rendered":"How to rewrite php echo with <<<qq"},"content":{"rendered":"<p><a href=\"http:\/\/stackoverflow.com\/users\/534755\/nikola\"><img loading=\"lazy\" decoding=\"async\" title=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" src=\"http:\/\/stackoverflow.com\/users\/flair\/534755.png\" rel=\"lightbox[1617]\" alt=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" width=\"208\" height=\"58\" \/><\/a><br \/>\nI&#8217;m a big fan of <a href=\"http:\/\/stackoverflow.com\/\">Stack Overflow<\/a> and I tend to contribute regularly (am currently in the <a href=\"http:\/\/stackexchange.com\/leagues\/1\/alltime\/stackoverflow\/2008-07-31\/534755?sort=reputationchange#534755\">top 0.X%<\/a>).\u00a0In this category (<a href=\"http:\/\/www.nikola-breznjak.com\/blog\/category\/stack-overflow\/\">stackoverflow<\/a>)\u00a0of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread <a href=\"http:\/\/meta.stackoverflow.com\/questions\/266971\/can-i-post-so-questions-and-answers-in-a-personal-blog\/266973\">here<\/a>.<\/p>\n<p>My <a href=\"http:\/\/stackoverflow.com\/questions\/5056758\/how-to-rewrite-php-echo-with-qq\">question<\/a> was:<\/p>\n<blockquote><p>I am wondering how to rewrite this code to work with qq:<\/p>\n<pre class=\"lang:default decode:true\">  $containerRight = &lt;&lt;&lt;qq\r\n    &lt;div class=\"container_right\"&gt;\r\n        {echoLikeBox()}\r\n\r\n        &lt;div class=\"join_us\"&gt;&lt;a href=\"#\"&gt;&lt;img src=\"images\/join_us.png\" width=\"304\" height=\"44\" alt=\"\"&gt;&lt;\/a&gt;&lt;\/div&gt;\r\n\r\n        &lt;div class=\"box2\"&gt;&lt;a href=\"#\"&gt;&lt;img src=\"images\/twitter_big.gif\" width=\"304\" height=\"292\" alt=\"\"&gt;&lt;\/a&gt;&lt;\/div&gt;\r\n\r\n        &lt;div class=\"box3\"&gt;&lt;a href=\"#\"&gt;&lt;img src=\"images\/facebook.jpg\" width=\"304\" height=\"257\" alt=\"\"&gt;&lt;\/a&gt;&lt;\/div&gt;\r\n\r\n        &lt;div class=\"box4\"&gt;&lt;a href=\"#\"&gt;&lt;img src=\"images\/google_ads.gif\" width=\"304\" height=\"164\" alt=\"\"&gt;&lt;\/a&gt;&lt;\/div&gt;\r\n    &lt;!-- container_right end --&gt;&lt;\/div&gt;;\r\n    qq;\r\n    echo $containerRight;<\/pre>\n<p>The problem is that I don&#8217;t know how to echo function inside the &lt;&lt;&lt;. The code for the echoLikBox() is this:<\/p>\n<pre class=\"lang:default decode:true\">function echoLikeBox()\r\n{\r\n    $likeBox = &lt;&lt;&lt;qq\r\n    &lt;div class=\"box1\"&gt;\r\n            &lt;div class=\"box1_lft\"&gt;&lt;a href=\"#\"&gt;&lt;img src=\"images\/tweet.jpg\" width=\"108\" height=\"20\" alt=\"\"&gt;&lt;\/a&gt;&lt;\/div&gt;\r\n            &lt;div class=\"box1_rht\"&gt;&lt;a href=\"#\"&gt;&lt;img src=\"images\/like.jpg\" width=\"82\" height=\"20\" alt=\"\"&gt;&lt;\/a&gt;&lt;\/div&gt;\r\n            &lt;div class=\"clear\"&gt;&lt;\/div&gt;\r\n    &lt;\/div&gt;&lt;!-- box1 end --&gt;\r\n    qq;\r\n    echo $likeBox;\r\n}<\/pre>\n<p>edit: found the solution here: <a href=\"http:\/\/stackoverflow.com\/questions\/104516\/calling-php-functions-within-heredoc-strings\">Calling PHP functions within HEREDOC strings<\/a><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>The answer, by user <a href=\"http:\/\/stackoverflow.com\/users\/528317\/gavin-anderegg\">Gavin Anderegg<\/a>, was:<\/p>\n<blockquote><p>You may want to change the &#8220;echoLikeBox()&#8221; function to, instead of echoing its contents, store them as a string. You can&#8217;t make a call to a function inside of heredoc strings, but you can output variables. So, for example, you could have:<\/p>\n<pre class=\"lang:default decode:true\">function echoLikeBox()\r\n{\r\n    $likeBox = &lt;&lt;&lt;qq\r\n    &lt;div class=\"box1\"&gt;\r\n            &lt;div class=\"box1_lft\"&gt;&lt;a href=\"#\"&gt;&lt;img src=\"images\/tweet.jpg\" width=\"108\" height=\"20\" alt=\"\"&gt;&lt;\/a&gt;&lt;\/div&gt;\r\n            &lt;div class=\"box1_rht\"&gt;&lt;a href=\"#\"&gt;&lt;img src=\"images\/like.jpg\" width=\"82\" height=\"20\" alt=\"\"&gt;&lt;\/a&gt;&lt;\/div&gt;\r\n            &lt;div class=\"clear\"&gt;&lt;\/div&gt;\r\n    &lt;\/div&gt;&lt;!-- box1 end --&gt;\r\nqq;\r\n    return $likeBox;\r\n}<\/pre>\n<p>and then just<\/p>\n<pre class=\"lang:default decode:true\">$likeBox = echoLikeBox();\r\n\r\n$containerRight = &lt;&lt;&lt;qq\r\n    &lt;div class=\"container_right\"&gt;\r\n        $likeBox\r\n\r\n        ...<\/pre>\n<p>inside of the main body.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%).\u00a0In this category (stackoverflow)\u00a0of posts I will will be posting&hellip;<\/p>\n","protected":false},"author":1,"featured_media":609,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-1617","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stack-overflow"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=1617"}],"version-history":[{"count":3,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1617\/revisions"}],"predecessor-version":[{"id":1679,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1617\/revisions\/1679"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/609"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=1617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=1617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=1617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}