How to shorten paths in PHP

Lets say I am configuring a module’s $basePath property in

protected/config/main.php

If I use the dirname() function to get the script’s path and calculate the path to the images folder, I get something like this -

C:/Wamp/www/yii/protected/config/../../images

But instead I would like -

C:/Wamp/www/yii/images

so that I can replace the common part

C:/Wamp/www/yii/

with

http://localhost/

to get the corresponding Url. Is there a way to do that? To be honest, I have never used regex before, so if there is a regex, please post it here.

realpath()

BTW General PHP Topics would be a better place for such questions, as they are not really Yii related.