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
   
		
About the author

About the 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, zambiatek 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

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button