Search code examples
phpsubstr

How to substring within the special character using PHP?


I need to sub-string the value within some special character using PHP. I am showing the original string below.

"name=G%20+%20l&cid=20"

In the above string I need the value within name= to next &.


Solution

  • Try this:

    $string = "name=G%20+%20l&cid=20";
    $explode_string = explode("&", $string);
    
    $explode_string2 = explode("name=", $explode_string[0]);
    echo array_pop($explode_string2);
    

    Output will be like:

    G%20+%20l