|
PHP網頁中用了for、foreach循環的地方,輸出的HTML縮進會出現混亂! |
一派護法 十九級 |
例如,源文件: <section> <?php for ($i = 0; $i < 10; $i++): ?> <p> <b><?=$i?></b> <span>X<?=rand()?></span> </p> <?php endfor; ?> </section> 輸出的卻是: <section> <p> <b>0</b> <span>X1205077112</span> </p> <p> <b>1</b> <span>X773379402</span> </p> <p> <b>2</b> <span>X887475260</span> </p> <p> <b>3</b> <span>X1876477515</span> </p> <p> <b>4</b> <span>X2052297116</span> </p> <p> <b>5</b> <span>X595908442</span> </p> <p> <b>6</b> <span>X1770538552</span> </p> <p> <b>7</b> <span>X1141881133</span> </p> <p> <b>8</b> <span>X1625491876</span> </p> <p> <b>9</b> <span>X255712361</span> </p> </section>
|
一派護法 十九級 |
有一個解決辦法,就是只要不縮進<?php for(...) ?>和<?php endfor; ?>這兩行。輸出內容就正常了。 <section> <?php for ($i = 0; $i < 10; $i++): ?> <p> <b><?=$i?></b> <span>X<?=rand()?></span> </p> <?php endfor; ?> </section> 輸出內容: <section> <p> <b>0</b> <span>X1161444442</span> </p> <p> <b>1</b> <span>X1671405940</span> </p> <p> <b>2</b> <span>X672291640</span> </p> <p> <b>3</b> <span>X1075579536</span> </p> <p> <b>4</b> <span>X1076265899</span> </p> <p> <b>5</b> <span>X1051557782</span> </p> <p> <b>6</b> <span>X1052304471</span> </p> <p> <b>7</b> <span>X545467228</span> </p> <p> <b>8</b> <span>X415250487</span> </p> <p> <b>9</b> <span>X152814961</span> </p> </section>
|
一派護法 十九級 |
<div> <article> <section> <?php for ($i = 0; $i < 10; $i++): ?> <p> <b><?=$i?></b> <span>X<?=rand()?></span> </p> <?php endfor; ?> </section> </article> </div> 無論HTML有多深,都不縮進for和endfor。
輸出: <div> <article> <section> <p> <b>0</b> <span>X810495393</span> </p> <p> <b>1</b> <span>X677610275</span> </p> <p> <b>2</b> <span>X1330714970</span> </p> <p> <b>3</b> <span>X1799954702</span> </p> <p> <b>4</b> <span>X444901469</span> </p> <p> <b>5</b> <span>X943932485</span> </p> <p> <b>6</b> <span>X1858610490</span> </p> <p> <b>7</b> <span>X2019841113</span> </p> <p> <b>8</b> <span>X346522515</span> </p> <p> <b>9</b> <span>X671290583</span> </p> </section> </article> </div>
|