小编Pro*_*mer的帖子

使用PHP从<option>标签获取文本

我想在<option>标签内部获取文本及其值.

<select name="make">
<option value="5"> Text </option>
</select>
Run Code Online (Sandbox Code Playgroud)

我用过$_POST['make']; ,我得到了价值,5但我想得到价值和文字.

我怎么能用PHP做到这一点?

php text get option

12
推荐指数
3
解决办法
3万
查看次数

如何使用Python解锁锁定的文件和文件夹(mac)

在我的脚本的主要目的完成后,作为"清理",调用一个函数来递归查看每个文件夹并删除以预定的一组扩展名结尾的所有文件.

我在测试期间,发现一些文件扩展名在删除列表中的文件实际上会抛出一个错误:[Errno 1] Operation not permitted: '/location/of/locked/file.png.查看文件本身,它似乎是锁定(在Mac上).

  1. 我如何使用Python从每个文件/文件夹中删除锁定属性(如果存在),然后删除文件,如果它在扩展名中结束?
    优选地,这可以在下面的相同功能中完成,因为遍历输入目录需要很长时间 - 只需处理一次即可.
  2. 这如何影响Windows上脚本的完整性?
    我已经开始对它进行编程,使其在操作系统之间兼容,但是(据我所知),Windows上不存在锁定属性,就像它在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)

python macos locked-files python-3.x

5
推荐指数
1
解决办法
1290
查看次数

将 JSON 字符串转换为 PHP 变量

我有一个带有 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)

我只需要得到temptext,并将其保存为变量......我该怎么办呢?

我尝试过编码、解码、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)

php json encode decode

2
推荐指数
1
解决办法
9312
查看次数

标签 统计

php ×2

decode ×1

encode ×1

get ×1

json ×1

locked-files ×1

macos ×1

option ×1

python ×1

python-3.x ×1

text ×1