Parse query string into an array

前端 未结 10 2569
暖寄归人
暖寄归人 2020-11-22 02:58

How can I turn a string below into an array?

pg_id=2&parent_id=2&document&video 

This is the

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 03:43

    If you're having a problem converting a query string to an array because of encoded ampersands

    &
    

    then be sure to use html_entity_decode

    Example:

    // Input string //
    $input = 'pg_id=2&parent_id=2&document&video';
    
    // Parse //
    parse_str(html_entity_decode($input), $out);
    
    // Output of $out //
    array(
      'pg_id' => 2,
      'parent_id' => 2,
      'document' => ,
      'video' =>
    )
    

提交回复
热议问题