Repository navigation
buildStaticPath
Helper method that translates .php URLs and query string parameters into clean, nested static HTML relative directory paths.
method(string $url, integer $depth = 0): string
url (string)
: The original internal URL string (e.g., index.php?page=2, blog.php?year=2026).
depth (integer)
: The current directory depth level used to prepend relative parent traversals (../). (default: 0) ^(optional)^
(string)
: Returns the transformed, static relative path ending in .html (with optional fragment hashes preserved).
📌 This method decodes HTML entities (
&->&) and replaces special characters in query values with underscores (_).If the base file name is
index, the folder prefix is omitted (index.php?page=2->page/2.html). Non-index controllers use the script name as the root directory (blog.php?year=2026->blog/2026.html).
$file->buildStaticPath('blog.php?year=2026&month=07&post=CoreyPHP-Is-Great', 0);
// Result: blog/2026/07/CoreyPHP_Is_Great.html
Input $url [^1] |
$depth [^2] |
Output Static Path [^3] |
|---|---|---|
index.php |
0 | index.html |
index.php?page=2 |
0 | page/2.html |
blog.php?year=2026&month=07 |
0 | blog/2026/07.html |
blog.php?year=2026&month=07&post=Top-Reviews |
0 | blog/2026/07/Top_Reviews.html |
index.php?category=music&instrument=piano |
0 | music/piano.html |
index.php |
2 | ../../index.html |
contact.php?ref=test#form |
1 | ../contact/test.html#form |
[^1]: Example PHP URLs supplied to method. [^2]: The URL depth if it applies. [^3]: The static HTML URLs returned.
- No debug errors.
endCode | startCode | writeHtml