Wednesday, October 22, 2025
HomeLanguagesPHP mb_parse_str() Function

PHP mb_parse_str() Function

The mb_parse_str() is an inbuilt function in PHP that is used to parse a string into variables. It is very similar to parse_str(). But it operates multibyte characters.

Syntax:

mb_parse_str($string, $result): bool

Parameters: This function accepts two parameters that are described below.

  • $string: Input query string parsed to in this parameter.
  • $result: This is the array parameter that holds the result in the form of decoded and encoded character values that are transformed.

Return Values: This function returns “true” if the function executes successfully otherwise it will return “false”.

Example 1: The following program demonstrates the mb_parse_str() function.

PHP




<?php
    $query = "book=harry+potter&author=Jk+Rowling&year=1997";
    $result = array();
    mb_parse_str($query, $result);
    print_r($result);  
?>


Output:

Array
(
   [book] => harry potter
   [author] => Jk Rowling
   [year] => 1997
)
 

Example 2: The following program demonstrates the mb_parse_str() function.

PHP




<?php
    $query
"fruits=apple%2Cbanana%2Ckiwi&vegetables=tomato%2Ccarrot%2Cspinach&drinks=water%2Cjuice%2Csoda";
    $result = array();
    mb_parse_str($query, $result);
    print_r($result);  
?>


Output:

Array
(
   [fruits] => apple,banana,kiwi
   [vegetables] => tomato,carrot,spinach
   [drinks] => water,juice,soda
)

Reference: https://www.php.net/manual/en/function.mb-parse-str.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS