第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

PHP 在 html 中創(chuàng)建空白

PHP 在 html 中創(chuàng)建空白

PHP
幕布斯6054654 2023-07-08 16:30:05
? <select id="selectedCountry"><?php? ? ? ? /*FETCH COUNTRY*/? ? ? ? $sql2 = "SELECT * FROM countries";? ? ? ? if($result2 = $conn -> query($sql2)) {? ? ? ? ? ? while($row2 = mysqli_fetch_assoc($result2)) {? ? ? ? ? ? ? ? ?>? ? ? ? ? ? ? ??? ? ? ? ? ? ? ? ? ? <option value="<?php echo strip_tags($row2['country_code']); ?>">? ? ? ? ? ? ? ? ? ? ? ? <?php echo strip_tags($row2['country_name']); ?>? ? ? ? ? ? ? ? ? ? </option>>? ? ? ? ? ? ? ? <?php? ? ? ? ? ? }? ? ? ? }?></select>while 循環(huán)內(nèi)部有空行和空白。我將該選項(xiàng)寫(xiě)在多行中,以使其看起來(lái)更好,但它輸出了空白。這是通常發(fā)生的情況嗎?如果不是,那么是什么原因?qū)е铝诉@個(gè)問(wèn)題呢?當(dāng)我 console.log 選定的國(guó)家/地區(qū)名稱時(shí),它包含空格。$( document ).ready(function() {var s = $("#selectedCountry" ).find(":selected").text();console.log(s);
查看完整描述

3 回答

?
德瑪西亞99

TA貢獻(xiàn)1770條經(jīng)驗(yàn) 獲得超3個(gè)贊

將選項(xiàng)寫(xiě)在一行中??瞻讓?huì)消失。

在多行中書(shū)寫(xiě)時(shí)創(chuàng)建空格是常見(jiàn)的行為。


查看完整回答
反對(duì) 回復(fù) 2023-07-08
?
30秒到達(dá)戰(zhàn)場(chǎng)

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超6個(gè)贊

我從來(lái)沒(méi)有真正關(guān)心過(guò)我的源代碼有多漂亮。如果您想完全控制源代碼間距,那么一種方法是打印 php 標(biāo)記內(nèi)的每個(gè)選項(xiàng)并手動(dòng)添加換行符 ( \n) 字符。\t如果您愿意,您甚至可以在每個(gè)選項(xiàng)標(biāo)簽之前添加一個(gè)制表符 ( )。

如果您的值實(shí)際上確實(shí)有多余的前導(dǎo)和尾隨空格,那么只需使用trim(),但我并不完全相信情況確實(shí)如此。

不要將過(guò)程語(yǔ)法與面向?qū)ο蟮?mysqli 語(yǔ)法混合在一起。我建議您繼續(xù)使用面向?qū)ο螅?jiǎn)潔且更易于使用。

mysqli 結(jié)果是一個(gè)可迭代對(duì)象——您不需要不斷調(diào)用 fetch 函數(shù)。

僅從數(shù)據(jù)庫(kù)中準(zhǔn)確選擇您想要使用的內(nèi)容。

代碼:(演示

<select id="selectedCountry">

    <?php

    if ($result = $conn->query("SELECT country_code, country_name FROM countries")) {

        foreach ($result as $row) {

            printf(

                "\t<option value=\"%s\">%s</option>\n", 

                trim(htmlentities($row['country_code'])), 

                trim(htmlentities($row['country_name']))

            );

        }

    }

    ?>

</select>


查看完整回答
反對(duì) 回復(fù) 2023-07-08
?
繁星coding

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個(gè)贊

那么你可以使用 php 本機(jī)函數(shù)刪除那些不需要的空格preg_replace('/\s+/', '', $row2['country_name']);


這是完整的代碼 $row2['country_name']


<select id="selectedCountry">

<?php

    /*FETCH COUNTRY*/

    $sql2 = "SELECT * FROM countries";

    if($result2 = $conn -> query($sql2)) {

        while($row2 = mysqli_fetch_assoc($result2)) {

            //Clear the data from html and remove unwante scape

            $countryName = preg_replace('/\s+/', ' ', strip_tags($row2['country_code']));

            ?>               

                <option value="<?php echo $countryName; ?>">

                    <?php echo $countryName; ?>

                </option>>

            <?php

        }

    }


?>

</select>

希望這有幫助!


查看完整回答
反對(duì) 回復(fù) 2023-07-08
  • 3 回答
  • 0 關(guān)注
  • 218 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)