Normalization of Shifted Paths When Parsing in PHP
Let's now learn how to normalize
relative shifted paths. Such
paths contain one or more
../ constructs, meaning
that we need to go up one folder level.
Let's look at an example. Suppose we have the following path:
<?php
$href = '../dir/page.html';
?>
Let the parser be accessing the following URL:
<?php
$url = 'http://targ.loc/cat/sat/';
?>
In this case, the normalized path will look as follows:
<?php
$norm = 'http://targ.loc/cat/dir/page.html';
?>
Implement a function that will perform normalization of paths of this type.
Let the parser be accessing the following URL:
<?php
$url = 'http://targ.loc/cat/sat/';
?>
Get all href on the page and
perform their normalization:
<a href="page.html">text</a>
<a href="dir/page.html">text</a>
<a href="../dir/page.html">text</a>
<a href="../../dir/page.html">text</a>