本文介紹了從 <option> 獲取文本使用 PHP 標記的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我想獲取 標簽內的文本及其值.
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
但我想同時得到值和文本.
I used $_POST['make'];
and I get the value 5
but I want to get both value and the text.
如何使用 PHP 來實現?
推薦答案
為了僅使用 PHP 獲取標簽和值,您需要將這兩個參數都作為值的一部分.
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
)
這是一種方法.
這篇關于從 <option> 獲取文本使用 PHP 標記的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!