Skip to content

Fix $request_uri replacement#23

Open
abetomo wants to merge 2 commits intomichaelfranzl:masterfrom
abetomo:fix-request_uri-replacement
Open

Fix $request_uri replacement#23
abetomo wants to merge 2 commits intomichaelfranzl:masterfrom
abetomo:fix-request_uri-replacement

Conversation

@abetomo
Copy link
Copy Markdown

@abetomo abetomo commented Sep 27, 2024

$request_uri may be headed by two slashes.

$uri_rel = '/path/no.php';
$request_uri = '/path/no.php/page';
echo str_replace( $uri_rel, '/', $request_uri );

// -> "//page"

If the same string exists in the path, it will not be replaced as expected.

$uri_rel = '/path';
$request_uri = '/path/path1/page';
echo str_replace( $uri_rel, '/', $request_uri );
    
// -> "//1/page"

So, we'll replace only the first one.

`$request_uri` may be headed by two slashes.

```php
$uri_rel = '/path/no.php';
$request_uri = /path/no.php/page';
echo str_replace( $uri_rel, "/", $request_uri );

// -> "//page"
```
If the same string exists in the path, it will not be replaced as expected.

```php
$uri_rel = '/path';
$request_uri = '/path/path1/page';
echo str_replace( $uri_rel, "/", $request_uri );

// -> //1/page
```

So, we'll replace only the first one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant