本文介紹了從 <option> 獲取文本使用 PHP 標(biāo)記的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
限時(shí)送ChatGPT賬號(hào)..
我想獲取 標(biāo)簽內(nèi)的文本及其值.
I want to get text inside the <option>
tags as well as its value.
示例
<select name="make">
<option value="5"> Text </option>
</select>
我使用了 $_POST['make'];
并且我得到了值 5
但我想同時(shí)得到值和文本.
I used $_POST['make'];
and I get the value 5
but I want to get both value and the text.
如何使用 PHP 來(lái)實(shí)現(xiàn)?
推薦答案
為了僅使用 PHP 獲取標(biāo)簽和值,您需要將這兩個(gè)參數(shù)都作為值的一部分.
In order to get both the label and the value using just PHP, you need to have both arguments as part of the value.
例如:
<select name="make">
<option value="Text:5"> Text </option>
</select>
PHP 代碼
<?php
$parts = $_POST['make'];
$arr = explode(':', $parts);
print_r($arr);
輸出:
Array(
[0] => 'Text',
[1] => 5
)
這是一種方法.
這篇關(guān)于從 <option> 獲取文本使用 PHP 標(biāo)記的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!