PHPStorm: PHP Syntax Highlighting editing / adding rules, and Customization - php

Hey I was looking around online and couldn't find anything about how to modify the syntax highlighting rules. I am trying to add a rule for PHP variables inside of double quoted strings. In Aptana they have a rule where these variables are highlighted which I find extremely useful as I do a lot with PHP vars inside double quoted strings. This is similar to the <<
I would also like to be able to specify sets of rules, for instance on heredocs:
<<<HTML
<html>
<div>$phpvar</div>
</html>
HTML
I want The html highlighted as HTML for specifically <<
Anyone know how to customized / edit the rules for the syntax highlighting?

Go into settings
File > Default Settings
There you can select how your code is formatted wrapped etc.
For colors go to:
Preferences > Editor (under IDE settings) > Colors & Fonts
There you can play around with colors, highlighting, background, fonts etc

Related

Atom beautify weird linebreaks

I have a weird bug. When I beautify my html/php mixed code it breaks the line and puts the echo and the following tag on 2 different lines making it look ugly.
Anyone had this problem before ?
BTW look at $answer_hash['topic_firstname'] suddenly the following )) are green/commented looks like.
Not sure, my only guess would be that you have softwrap (also called wordwrap) on. You can disabled it at: View -> Toggle softwrap.
To awnser your second question, the value="" attribute normal contains string, and not code. So it gets the green color as if it is a string.
You're using the standard syntax theme that doesn't give a color to parentesis and curly braces, so since it's in a value="" attribute it gets the green color.
It's default behavior of PHP-CS-Fixer (I assume you use the default PHP beautifier of atom-beautify in version 2) to break lines after curly braces.
The body of each structure MUST be enclosed by braces. Braces should
be properly placed. Body of braces should be properly indented.
Scroll down to 'braces [#PSR2, #Symfony]'
Which is defined in the PSR-2 coding style guide:
Opening braces for control structures MUST go on the same line, and closing
braces MUST go on the next line after the body.
If you switch back to version 1 in the atom-beautify settings it won't do the line breaks but it stop fixing other things only available in version 2.
For completeness (although rpm192) has already answered the second part of your question: The )) are green because the standard color for html attribute values is green. Since your document type is set to PHP, all built in functions, arrays etc. between PHP-tags are colored differently but everything else, which does not have a different color specified, keeps it's previous color (which in this case is green). As you can see in the screenshot if you place the PHP-code outside of the html attribute value the braces are colored white as usual.
Note: You have more opening curly braces { than closing ones. Check out line 6 in my screenshot.

How do I edit highlighting for built-in functions for PHP in Notepad++?

Question: Can someone tell me where to add, in Notepad++, syntax highlighting for built-in functions in PHP?
There are a few built-in functions in PHP that Notepad++ does not highlight. One I have noticed is "real_escape_string."
The langs.model.xml file includes the words to be highlighted with the languages supported by Notepad++.
The langs.model.xml file is found at
C:\Program Files\Notepad++\langs.model.xml
At the top of that file it says the following:
"The key words of the supported languages, don't touch them!"
I edited the file anyway. I included "real_escape_string" within keywords in the PHP section. It did not work. The real_escape_string function was not highlighted.
I cannot find a way to add syntax highlighting for built-in functions from the user interface.
Under "Settings -> Preferences" I have looked at all the options and there is no option to edit syntax highlighting
Under "Settings -> Style Configurator" there's no place to edit syntax highlighting
Thank you in advance.
%appdata%/Roaming/Notepad++/langs.xml
Keywords for PHP are located around line 172
Add the keywords that you wish to highlight between the <keywords> <keywords?> tags then restart notepad++

htmlentities in PHP - differences between local and live

I edit certain pages of my website via textarea's and a common WYSIWYG editor. This editing frequently requires me to display HTML code by using <pre> tags.
Due to the nature of the textarea, I believe I'm required to use htmlentities in order to conserve HTML Entities such as < (which is translated to <), so here is what I did:
<textarea name="resume" class="ckeditor"><?php echo htmlentities($e['resume']) ?></textarea>
This works great locally, my syntax highlighter works great in the pre tags, the textarea doesn't convert the HTML Entities when being edited.
So I try hosting this project, but on live there is a problem, all double quotes are being displayed as \" , there is a slash before all double quotes in my text.
Is this something I should take up with my host? I don't understand how locally this issue isn't happening.
You have Magic Quotes enabled on the live site.
Look at the documentation for magic_quotes_gpc: http://php.net/manual/en/info.configuration.php#ini.magic-quotes-gpc
You can take it up with your host, but you can also disable it in a .htaccess file: http://php.net/manual/en/security.magicquotes.disabling.php

vim php_javascriptInStrings option?

I noticed that the syntax/php.vim file on my ubuntu machine has a php_htmlInStrings option. I can turn this option on to display HTML syntax highlighting within strings in my php files, which is great. I would also like to do javascript syntax highlighting within strings in a php file. Does anybody know if this can be done and if so how can I do it?
edited - added extra possibilities
I should also mention that I would be happy with a solution where i have to parse all my javascript strings though a php function before outputting the result. This might get around the problem suggested by conner below where vim has trouble deciding if the string contains javascript. for example:
$js = "some regular text which is not javascript##now vim has
detected that this part is javscript##back to regular text";
parse($js);
function parse($str)
{
return str_replace('##', '', $str);
}
The reason I would be happy to do this is because I will probably be incorporating a html/css/js variable minifier into my project which will be doing substitutions on strings anyway.
Of course if there is a vim-specific equivalent character for ## which will not show up in the source code and would not need to be filtered out then this would be preferable...
re-edit 2
As per conner's solution below, the desired effect can be achieved like so:
$js = "<script>some javascript</script>";
(with :let php_htmlInStrings=1 in vim). If somebody can show me the vim script required to get the javascript syntax highlighting to show up in the following string then I will award them the answer:
$js = /*<script>*/"some javascript"/*</script>*/;
I think the general problem with this is that vim needs a way to differentiate between the javascript and HTML highlighting. In HTML files, vim determines this based on the <script></script> tags within it to apply the javascript highlighting. If you put <script></script> tags in your string you'll see that this is the case. However, if you take those away then vim has no way of knowing if the content in your string is HTML or javascript. You could remedy this by editing adding something to signify that it's javascript that hopefully wouldn't effect the resultant code, but this is tricky. You can see where the HTML file is setting the <script></script> tag specification on line 167 of $VIMRUNTIME/syntax/html.vim. It looks like this:
syn region javaScript start=+<script[^>]*>+ keepend end=+</script>+me=s-1 contains=#htmlJavaScript,htmlCssStyleComment,htmlScriptTag,#htmlPreproc
Have you tried this php.vim syntax file?

Disable vim angle bracket highlighting in HAML template

I'm using PHP in some HAML templates, so I've got a lot of <?php echo ...?> going on. Vim is highlighting all the greater-than signs with the ErrorMsg highlighting group, but it gets quite annoying, as you can see:
What's the best way to disable this for HAML templates?
If all else fails, you could forcibly remove the highlighting for angle brackets with these commands:
:syn match Normal '<'
:syn match Normal '>'
You can change the syntax highlighting for specific file types in vim. So for .haml files put something in your .vimrc like:
au BufNewFile,BufRead *.haml set filetype=haml
then make a haml.vim file in your home/.vim/ folder.
Also check out this link

Categories