Atom comments are incorrect - php

When I toggle comments in PHP with Atom, it always comment as HTML, even if the file extension is PHP. Example :
<!-- <?php echo "Test"; ?> -->
instead of
// <?php echo "Test"; ?>
Is there a way to fix that? I tried in atom --safe mode, but it doesn't help. Thanks!

I think that it is a normal behaviour. Because all around php tags is html code.

Related

switching between php and html in sublime while working in a file

hi every body here is my first question in stackoverflow :)
I'm new to php and sublime text. my question is: is there any way to switch between php and html in sublime text while you'r working in a file consists of both php and html?
what I mean is switching syntax highlighting, code snippets and etc.
for example consider this code:
<?php
echo <<<_HTML
<!--html code comes here
-->
_HTML;
?>
I know I can change view>syntax, however other things stay on php, fore example while i'm on html part i can not close tags by "alt+." and "ctrl+/" insert "//" instead of
<!-- -->
thanks in advanced.
Well, the simplest would be to actually get out of PHP and into HTML by closing the php tag:
<?php
for($i=0; $i<10; $i++)
{
?>
<p>This is a paragraph</p> <!--html comment-->
<?php
} //this is php comment
?>

PHP inspection reports CSS selector unused. It is used by a PHP echoed Tag

I have PHP code which creates an HTML
echo('<div id="keyboard">');
In my CSS I have
#keyboard {
}
PHPStorm reports the CSS selector is not used. It is used. Can I make it realize that? In not, I once saw some way of disabling a single error or warning, but I can no longer find that in the documentation.
What you can try is to move the html out of the php script and just open the parentheses when needed. I suspect that the IDE cannot distiguish between php echoed html and html outside of php tags.
<?php
//add php code here
?>
<div id="keyboard">
<?php
//php code here
?>
</div>
<?php
//add php code here
?>
The IDE should now be able to match the CSS with the relavant id.

incorprating css and html elements into php

I have a bunch of php files that I want to incorporate html (divs) and css (external stylesheets) elements into.
If any one has any tips / ideas on how to go about doing this I'd love to hear them :)
You could either :
Integrate HTML code in your PHP file,
Or have your PHP script echo the HTML content.
With the first solution, your PHP file could look like this :
<?php
$var = 10;
// some PHP code
?>
<div>
this is some HTML
</div>
<?php
// and some PHP code again
?>
For more informations about this, see the following section of the manual : Escaping from HTML.
While, with the second solution, your PHP file could look like this :
<?php
$var = 10;
// some PHP code
echo '<div>this is some HTML</div>';
// and some PHP code again
?>
Basically, you are free to mix HTML and PHP code in the same PHP script : outside of <?php ... ?> tags, things will not get interpreted as PHP code.
All you need to do is exit php and write html as normal:
<?php
// php code
?>
<div>
<p>Some html</p>
</div>
<?php
// more php code
?>
Take a look at the PHP alternative syntax for control structures. It is often times more comprehensive when you start mixing with plain HTML:
<?php if(...): ?>
<p>paragraph</p>
<?php endif; ?>
Instead of:
<?php if(...) { ?>
<p>paragraph</p>
<?php } ?>

How do I tell Netbeans that a section of code is Javascript?

I'm using the Zend Framework's javascript helpers of the form:
<?php $this->headScript()->captureStart(); ?>
//Javascript here
<?php $this->headScript()->captureEnd(); ?>
//Rest of view here
The problem is that Netbeans keeps complaining about code problems in the block, because it thinks it's an HTML, rather than a Javascript, block. Plus syntax coloring is broken.
Netbeans already has special comment hinting which you can use to apply a type to a variable when it can't be resolved by Netbeans automatically to tell it that we're writing Javascript in that range, rather than HTML?
Something like this:
<?php $this->headScript()->captureStart(); ?>
//<script type="text/javascript">
var validJSsyntax = true,
netbeansJShighlighting = true,
problem = 'solved';
//</script>
<?php $this->headScript()->captureEnd(); ?>
Of course it will produce two useless lines in your JS output, but you can modify captureEnd() method to strip those for you.
From my knowledge this functionality is not yet implemented in the current version of NetBeans IDE that is 6.9.1. I can show you a workaround through which you can fool the NetBeans IDE to highlight the Javascript as a script section, and also keeps the PHP processor happy. It will look like following code snippet:
<?php $this->headScript()->captureStart(); ?>
<?php if( false ) {?><script><?php } ?>
// keep Javascript here
<?php if( false ) { ?></script><?php } ?>
<?php $this->headScript()->captureEnd(); ?>
I have tested this in NetBeans IDE 6.9.1
I was actually just reading about this yesterday in their blog:
Their HTML in PHP parsing has been flaky, especially with indenting incorrectly short/alternate form code, but the latest nightly builds (I presume those after 201010060000) have improvements in that area. I haven't tried it yet but give it a shot.
print problematic code with PHP
<script <?PHP echo 'type="text/template"?> id="Template-1">
//your code here
</script>
If you print all script tag with PHP, NetBeans perfectlly format HTML tags

How do HTML comments work with PHP code?

I just wonder how does html comment tag work with php code.
If I have the following code, does php parse it anyway?
<!--
<?php
echo "hi";
?>
-->
a simple question, but I guess it is important to know.
Oh yes, anything in PHP blocks gets executed, but in this case, it isn't shown to the end user because it's in HTML comments.
In the source of the page that is generated by this PHP script, you will see the output surrounded by HTML comments, simple as that.
The only way comments will affect the output of a PHP script is with valid PHP comments.
Yes it does. If that is between <?php ?> tags
You can use PHP comments /* commment */ and they won't execute.
As a side note to the answers above: You can also interrupt the HTML comment:
<!--
<?php
echo "-->This will be seen!<!--";
?>
-->
gives this output:
<!--
-->This will be seen!<!---->

Categories