• 15

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I'm using Sublime Text with the Pastels on Dark theme. My language of choice is PHP. How can I get HTML syntax highlighting inside PHP strings & heredoc syntax?

      • 2
    • When you add HTML outside of PHP then you have to turn output buffering on and the turn it off again to capture the HTML. Also there will be all these snippets like: It makes the code a lot less easy to read. I don't like your idea Mark.
    • Still need to know how to do it with strings, but I found the answer to half of my question. In heredoc syntax you use the name of the language for the delimiters. I.E. $o = <<
    • If you're manipulating big HTML strings inside PHP, it feels like you're doing something weird and/or wrong. Any large chunks of HTML belong outside the blocks, where it gets syntax-highlighted properly..

Name your heredocs after the language you are using. This will syntax highlight in many text editors, including Sublime Text.

For example:

echo <<<HTML
<!-- put HTML here and it will have syntax highlighting -->
  • 16
Reply Report
      • 1
    • I also just realized you can use {$myAry['subIdx']} to put any kind of variable into your heredoc syntax. Function calls can't be placed inside them but you can set the return value to a variable before the heredoc, then use that.

Wanted to add this as a comment to Ol' Reliable's answer but I am not allowed yet.

Whilst coding outside and then copying in can be a hassle, for people/editors without syntax highlighting in heredoc, an easy workaround is to temporarily add a closing php tag to the heredoc opening tag:

$myHtmlCode = <<<HTML?>
    <h1>I am Highlighted</h1>
    <p>Remove the closing php tag above to finish editing</p>
  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions