As Inserting code HTML in PHP and other Tricks

As Inserting code HTML in PHP and other Tricks

Nowadays that the Development Web has changed very many, with as much CMS, WordPress€¦ and a long etc, every time is except the developers Web that we pricked PHP. Now to implement a system of users within a coarse Web with installing plugin from repositorio and dragging it with the mouse to a bar of widgets€¦ (hands at the top).

Personally I am not very in favor of this type of platforms, although lately I have had cede territory and to adapt, since within them €œprogram€ and results rather faster are obtained.
For that they continue pricking code PHP small hand, creating their functions, or simply they like or they begin this land€¦ go a pair of advice here who perhaps can serve to them as help to insert code HTML in PHP.

    <? php/*c³digo php€¦ * PRINT <<<HERE/* within this PRINT we will be able to prick code HTML, and will be interpreted without trouble * HERE;? >

    What we are doing is to detail an area of PRINT between two points defined within code PHP, so that interprets the HTML that we include in him.

    This method can be used to us for simple codes with basic conditions, but the code is more complex, this method can be muddied and to give syntax errors us, and already sabeis that an error in PHP gives back a €œnothing to us€, that I know does not have €œto purify step by step€ for PHP, so we would become crazy half.
    In order to solve this problem I show another cleaner method to you.

    <? php if ($a==$b) \ {? >/*aqu­ we pricked code HTML*/<? php}? >

    Supposing that we had conditional or other options and we wanted to show some results in screen with HTML following the results of conditions PHP, this method is clean, effective and gives rise the less to syntax errors. What we observed in the image is simply that we can open or close a key \ {} in PHP when we need it, and to include code HTML to our taste there inside when? php is closed.


    <? php if ($a==$b): >/*aqu­ we pricked code HTML*/<? php endif? >

A simple example of the use of applied method 2 would be:

<? php $ip = $_SERVER [€˜REMOTE_ADDR€™];
/*FUNCI“N THAT GATHERS the IP OF the USER WHO SAILS IN THIS PGINA*/if ($ip== \ {? > <h1>ERES a HEAVY LENGTH OF MY WEB</h1>/*Si the IP is the one of the heavy user I show in screen this t­tulo*/to him              
<? php}? > <? php else \ {? isn't > <h1>BIENVENIDO WEB</h1>/*si the IP of the user the one of the heavy one, I show to this other t­tulo*/to him <? php}? >

I hope that this article serves to you as help,
A greeting,

By “scar Carrillo