我想在<option>标签内部获取文本及其值.
例
<select name="make">
<option value="5"> Text </option>
</select>
Run Code Online (Sandbox Code Playgroud)
我用过$_POST['make']; ,我得到了价值,5但我想得到价值和文字.
我怎么能用PHP做到这一点?
在我的脚本的主要目的完成后,作为"清理",调用一个函数来递归查看每个文件夹并删除以预定的一组扩展名结尾的所有文件.
我在测试期间,发现一些文件扩展名在删除列表中的文件实际上会抛出一个错误:[Errno 1] Operation not permitted: '/location/of/locked/file.png.查看文件本身,它似乎是锁定(在Mac上).
REMOVE_FILETYPES = ('.png', '.jpg', '.jpeg', '.pdf')
def cleaner(currentPath):
if not os.path.isdir(currentPath):
if currentPath.endswith(REMOVE_FILETYPES) or os.path.basename(currentPath).startswith('.'):
try:
os.remove(currentPath)
print('REMOVED: \"{removed}\"'.format(removed = currentPath))
except BaseException as e:
print('ERROR: Could not remove: \"{failed}\"'.format(failed = str(e)))
finally:
return True
return False
if all([cleaner(os.path.join(currentPath, file)) for file in os.listdir(currentPath)]):
try:
os.rmdir(currentPath)
print('REMOVED: \"{removed}\"'.format(removed = currentPath))
except:
print('ERROR: Could not remove: \"{failed}\"'.format(failed = currentPath))
finally:
return True …Run Code Online (Sandbox Code Playgroud) 我有一个带有 Yahoo Weather API 数据的 JSON 数组:
"query":{
"count":1,
"created":"2015-09-08T15:33:25Z",
"lang":"en-US",
"results":{
"channel":{
"item":{
"condition":{
"code":"30",
"date":"Tue, 08 Sep 2015 11:13 am EDT",
"temp":"81",
"text":"Partly Cloudy"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我只需要得到temp和text,并将其保存为变量......我该怎么办呢?
我尝试过编码、解码、subtr 和其他一些方法,但似乎无法获得正确的语法。我已经尝试过将 JSON 字符串转换为 PHP 数组的说明
这是我网站上的代码:
$BASE_URL = "http://query.yahooapis.com/v1/public/yql";
$yql_query = 'select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text="'.$city.', '.$state.'")';
$yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json";
// Make call with cURL
$session = curl_init($yql_query_url); …Run Code Online (Sandbox Code Playgroud)