Birlikisgu
Birlikisgu

Reputation: 329

why my php code create unneccesary spaces?

This my php code. this is creating to html codes that is below.

foreach($sorular->soruCek($_GET["kategori"]) as $data)
{
    $kontrol = $sorular->cevapCek($data["id"]);
    if($kontrol)
    {
        echo $data["soru"] . '<br/>';
            foreach(@$sorular->cevapCek($data["id"]) as $veri)
            {
                ?>
                <input type="radio" name="soru<? echo $data["id"]; ?>" value="<? echo $veri["id"]; ?>"/><? echo $veri["cevap"]; ?>
                <?
                echo "<br/>";
            }
        echo "<br/>";
    }
}

Result: enter image description here

Upvotes: 0

Views: 56

Answers (1)

Mike B
Mike B

Reputation: 32145

PHP is a templated language. Any spaces outside of php tags are sent to the browser.

<?php $a = 'foo';?>
                        <input type="string" />
<?php $b = 'bar';?>

Input will be indented that many spaces. Regarding 'formatting' your html markup:

1) Don't worry about formatting your HTML as long as it validates or displays correctly in the browser.

2) You should be minifying your output anyway, eliminating those spaces.

3) If you really want your HTML to be prim-and-proper you can use Tidy on your output.

Upvotes: 5

Related Questions