Multiple PHP Tags

This is just a general PHP question. Does it help or hurt to have a few <?php CODE ?> In my scripts?

I just looked at some of my scripts and noticed that some of them have 3-4. I don’t know if this causes any slowdown on my site or not :)

+7
source share
5 answers

No, it does not cause any slowness or problems. This is completely common when there are tens or hundreds of separate <?php ?> Blocks in templates.

+12
source

I assume that you mean a few opening and closing PHP tags.

As in the case when you want to respond to a large HTML markup block, is it always better to close the php tag? > and then run it again when necessary. For example:

 <?php if($ok) { ?> A large block HTML MarkUp text <?php } //End of if($ok) ?> 

This actually improves speed, because the control will not analyze the entire large block listed above and simply move on to the next <? php or if the endpoint is compared to echoing all of these lines.

+3
source

You can read about it in the documentation .

+2
source

If you use it embedded in html pages (and I think you if you have a lot of PHP blocks), that’s fine, and I don’t think there is a way to avoid this.

If you have an external script, there is no reason to have multiple blocks. Although I do not think that this will affect performance.

+1
source

no, it does no harm, but if you do this, for example:

 <div><?php echo $x; ?></div> 

You can use short tags (if included in your php configuration)

 <div><? echo $x; ?></div> 

If you want to try to reduce the number of php tags, you can even echo html like this:

 echo '<div>'.$x.'</div>'; 
0
source

All Articles