src/Sulu/Component/Rest/RestController.php
public function replaceOrAddUrlString($url, $key, $value, $add = true)
    {
        if ($value) {
            if ($pos = strpos($url, $key)) {
                return preg_replace('/(.*' . $key . ')([\,|\w]*)(\&*.*)/', '${1}' . $value . '${3}', $url);
            } else {
                if ($add) {
                    $and = (false === strpos($url, '?')) ? '?' : '&';

                    return $url . $and . $key . $value;
                }
            }
        } else {
            // remove if key exists
            if ($pos = strpos($url, $key)) {
                $result = preg_replace('/(.*)([\\?|\&]{1}' . $key . ')([\,|\w]*)(\&*.*)/', '${1}${4}', $url);

                // if was first variable, redo questionmark
                if (strpos($url, '?' . $key)) {
                    $result = preg_replace('/&/', '?', $result, 1);
                }

                return $result;
            }
        }

        return $url;
    }
public function replaceOrAddUrlString($url, $key, $value, $add = true)
    {
        if ($value) {
            if ($pos = strpos($url, $key)) {
                return preg_replace('/(.*' . $key . ')([\,|\w]*)(\&*.*)/', '${1}' . $value . '${3}', $url);
            } else {
                if ($add) {
                    $and = (false === strpos($url, '?')) ? '?' : '&';

                    return $url . $and . $key . $value;
                }
            }
        } else {
            // remove if key exists
            if ($pos = strpos($url, $key)) {
                $result = preg_replace('/(.*)([\\?|\&]{1}' . $key . ')([\,|\w]*)(\&*.*)/', '${1}${4}', $url);

                // if was first variable, redo questionmark
                if (strpos($url, '?' . $key)) {
                    $result = preg_replace('/&/', '?', $result, 1);
                }

                return $result;
            }
        }

        return $url;
    }
public function replaceOrAddUrlString ( $ url , $ key , $ value , $ add = true ) { if ( $ value ) { if ( $ pos = strpos ( $ url , $ key ) ) { return preg_replace ( '/(.*' . $ key . ')([\,|\w]*)(\&*.*)/' , '${1}' . $ value . '${3}' , $ url ) ; } else { if ( $ add ) { $ and = ( false === strpos ( $ url , '?' ) ) ? '?' : '&' ; return $ url . $ and . $ key . $ value ; } } } else { // remove if key exists if ( $ pos = strpos ( $ url , $ key ) ) { $ result = preg_replace ( '/(.*)([\\?|\&]{1}' . $ key . ')([\,|\w]*)(\&*.*)/' , '${1}${4}' , $ url ) ; // if was first variable, redo questionmark if ( strpos ( $ url , '?' . $ key ) ) { $ result = preg_replace ( '/&/' , '?' , $ result , 1 ) ; } return $ result ; } } return $ url ; }
function replaces a url parameter.

@param string $url String the complete url
@param string $key String parameter name (e.g. page=)
@param string $value replace value
@param bool $add defines if value should be added

@return mixed|string

@deprecated
function replaces a url parameter .