获取地址并删除斜杠

I have a web address like this :

test.project-heberg.fr/admin/test.php

I want to put in a var only this part :

test.project-heberg.fr/

How can I do it ? Thanks in advance.

explode will do the trick

 $string = "test.project-heberg.fr/admin/test.php" 
 $res= explode("/", $string);
 echo $res[0]."/"; // test.project-heberg.fr/

or using strstr

$res   = strstr($string, '/',true);
echo $res."/"; // test.project-heberg.fr/

I guess you want to know the hostname? so use the following code:

$_SERVER['SERVER_NAME']

or

$_SERVER['HTTP_HOST']

All server vars are found here: http://www.php.net/manual/en/reserved.variables.server.php

Good luck!

you can do it many ways. one of the suggested way is..

  $a= "test.project-heberg.fr/admin/test.php";
  $b = strstr($a, "/",TRUE)."/";
  echo $b;

use::

$str = "test.project-heberg.fr/admin/test.php";
echo strstr($str, '/', true) . "/";