How to use the PHP parser only? - codemirror

All modes for CodeMirror that I've found use PHP parser as multi parser combined with HTML and JavaScript. All these require <?php to start highlighting PHP.
I want to have everything in my textarea highlighted as PHP. Assume <?php at the beginning and ignore any further ?>.
Can I do this?

Use "text/x-php" as your mode option.

Related

How to add PHP syntax highlighting in Pug files?

I need to write PHP code in Pug files for a project.
How can I extend pug syntax highlighting with PHP syntax, without recreating a full language syntax?
For example, for this piece of code, I would like that PHP code be colored like a regular .php file and keep at the same time pug syntax highlighting.
section
.container
.row
.col
.image-100-wrapper
<?= wp_img($content['image'], 'large') ?>
.row.justify-content-center.mt-5
.col-auto
<?php wp_btn($content['bouton']) ?>
I looked if there was an existing VS code extension that does what I am looking for and I searched if there was a simple way to edit the .pug TextMate rules, but I didn't find it.

tinymce code inserting, can't get it to work

I enabled codesample plugin https://www.tinymce.com/docs/plugins/codesample/
and to test it I entered just head tag like this
and it displays like this in the editor
when I save this to database it gets saved like this:
<pre class="language-markup"><code><head></code></pre>
When I reload the page all i get is this in the editor
<pre> </pre>
Database still looks like
<pre class="language-markup"><code><head></code></pre>
but there is no head tag visible in the editor. Any ideas why?
When placing raw HTML into a <textarea> you need to properly escape the HTML code that you are placing in the <textarea>. As you are not doing that the browser (and by proxy TinyMCE) is "cleaning up" the invalid markup as best as it can.
You can either:
Properly escape the HTML
Use the setContent() API to load your HTML
into TinyMCE (as opposed to injecting the HTML into the <textarea>)
I would personally suggest the second option above as it completely eliminates the vagaries of injecting HTML into a <textarea>.
If you want to try the first solution I listed above you might do something like this if you were using PHP
<?php
$content = "This string contains the TM symbol: ™";
print "<textarea>". htmlentities($content) ."</textarea>";
?>
Every language I have used has some equivalent to htmlentities().

Netbeans: Syntax Highlighting -- multiple languages per file

The majority of the pages I author contain both HTML and PHP. It would appear that in Netbeans you can have syntax highlighting for one or the other by setting the associated file types.
Coming from Notepad++, I've always taken for granted the fact that I could use php, css, html, javascript all in one file and retain syntax highlighting for all of them.
Is this possible in Netbeans?
I think the answer here is that Netbeans DOES support multiple language, but it will only get it right if there's something hinting at the "inner" language. When I exit PHP with ?> NetBeans tends to format what comes before the next <?php as HTML automatically. Not sure if that is working for you. Maybe you were trying to get highlighting in a string like $output = "<some><html";. I think you can imagine why that second one wouldn't work.
For JS, for example, it seems to look for the <script type="text/javascript">, and stuff inside gets the JS highlighting even if the file type is PHP.
This other question has a great solution for "tricking" Netbeans into rendering your JS output by PHP into being formatted, even when your code doesn't have a <script type="text/javascript"> tag.

Zend Forms or simple html forms

It is mandatory to use a Zend Form everytime I need one? Can I do it with a simple html form in my phtml?
Are there dangers or trouble using the html one?
You can still use pure html forms wherever you want.
Zend_Forms try to help to easily implement the best pratices particularly validating, filtering and escaping user input. If you use pure HTML, you may forget these best pratices.

TinyMCE escapes some especial characters

When, for example, I write this HTML with tinyMCE:
<p>asdasd</p>
<p class="relevant">asd</p>
<p>as</p>
the php that receives the form post prints the next:
<p>asdasd</p>
<p class=\"relevant\">asd</p>
<p>as</p>
How can turn off this behavior?
Thank you in advance
This is most likely due to the MagicQuotes feature in PHP and is covered in the TinyMCE FAQ.
The simplest way to deal with this is to disable the feature, especially as it has been deprecated as of PHP 5.3.0
An alternative is to clean up the results using
stripslashes($_POST['text']);