How i can earn variable from string in PHP? [closed]

This should work for what you are trying to achieve

    $string = "domain.ou/path?query=test"; 
    $str_arr_domain = explode ("/", $string);
    $str_arr_params = explode ("?", $string);
    
    
    $newpath = "/api/path2/";
    
    $final_url = $str_arr_domain[0].$newpath.$str_arr_params[1];
    
    
    print_r($final_url);

Leave a Comment