NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
HTML code completion in PHP?


Joined: 22 Oct 2011
Posts: 2
Reply with quote
Hi,

how do I get this working?

Settings - Code Insight - Code Completion
is enabled, min chars = 2, HTML tab everything is checked, PHP tab everything without "limit scope to includes"

I want to type in e.g. "<p" in PHP parts of my script to get the full tags "<p></p>"
but this is only working in non PHP code parts atm...

Tia,
highend
View user's profileFind all posts by highendSend private message
Guru master

Joined: 24 Jul 2009
Posts: 737
Reply with quote
I think the only place you can get HTML code completion within PHP is by using ?> to switch out of PHP context and back into HTML. This means for example that code completion is not available within strings on PHP statements because PhpED has no way of knowing if that should be an HTML string or not.

Code:
<?php
// My PHP stuff is here
echo "<p>HTML code completion not available within this string</p>";
?>
<p>But code HTML code completion is available here because we are in HTML context</p>
<?php
// And back to PHP again
?>


You can of course do things like this:

Code:
<?php
  if (TRUE):
?>
<p>Output some HTML if the condition is true</p>
<?php
  endif;
?>
View user's profileFind all posts by plugnplaySend private message


Joined: 22 Oct 2011
Posts: 2
Reply with quote
Thank you for the explanation, plugnplay.
View user's profileFind all posts by highendSend private message
Guru master

Joined: 24 Jul 2009
Posts: 737
Reply with quote
It's worth mentioning at this point that if a PHP file finishes in PHP context, whilst you can use a terminating ?> and that appears to be the correct thing to do, most framework standards say that you should not use a terminating ?>

The reason for that is so there is less chance of inadvertently outputing blank HTML at the end of the file (such as hard to spot new lines and spaces) which will cause HTML headers to be sent.

So whilst my previous sample is technically correct and most code snippets do show the terminating ?> this is what you might really have in your PHP file:

Code:
<?php
  if (TRUE):
?>
<p>Output some HTML if the condition is true</p>
<?php
  endif;
View user's profileFind all posts by plugnplaySend private message
HTML code completion in PHP?
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic