Reply to Re: recognize url where file is

Your name:

Reply:


Posted by denisb on 10/01/07 14:03

artev <mailnotspammm@notspamm.nn> wrote:
> If I am in http://localhost/A/test.php
> I want in php a code (or function) that print:
> http://localhost/A/
> is there a function that to do all?

have a look at <http://fr2.php.net/manual/en/function.parse-url.php>
(comment by kjensen_at_nospam_dot_iaff106_dot_com at bottom of the page)

<?php

function ParseURLplus($url) {
$URLpcs = (parse_url($url));
$PathPcs = explode("/", $URLpcs['path']);
$URLpcs['file'] = end($PathPcs);
unset($PathPcs[key($PathPcs)]);
$URLpcs['dir'] = implode("/", $PathPcs);
return ($URLpcs);
}

$url1 = 'http://www.example.com/path/dir/file.php?arg=val#anchor';
$URL1pcs = ParseURLplus($url1);
print_r($URL1pcs);

/*
Array(
[scheme] => http
[host] => www.example.com
[path] => /path/dir/file.php
[query] => arg=val
[fragment] => anchor
[file] => file.php
[dir] => /path/dir
)
*/

$url2 = 'https://name:pass@www.example.com/dir/file.php?arg=val#anchor';
$URL2pcs = ParseURLplus($url2);
print_r($URL2pcs);

/*
Array(
[scheme] => https
[host] => www.example.com
[user] => name
[pass] => pass
[path] => /dir/file.php
[query] => arg=val
[fragment] => anchor
[file] => file.php
[dir] => /dir
)
*/

?>

HTH
--
@@@@@
E -00 comme on est very beaux dis !
' `) /
|\_ =="

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация