Problem when i am using $webRoot / $srvRoot as a value for a variable or in defining a constant
Code & problem is below:

<?php 

ini_set('display_errors', 'On');
error_reporting(E_ALL);
$thisFile = str_replace('\\','/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];

$webRoot =  str_replace(array($docRoot, 'testing.php'), '', $thisFile);
$srvRoot = str_replace('testing.php', '', $thisFile);


define('WEB_ROOT', $webRoot); //error on this line Variable Undefined
define('SRV_ROOT', $srvRoot); //error on this line Variable Undefined

echo 'thisFile- '.$thisFile ;//works perfect
echo "<br>";
echo 'docRoot- '.$docRoot;//works perfect
echo "<br>";


echo 'webroot- '.$webRoot ;//works perfect

echo "<br>";
echo 'srvroot- '.$srvRoot ;//works perfect
?>

what is it that i am doing wrong?

Pls help me!

First of all, it is only providing a Notice.It isn't a show stopper. The PHP interpreter seems to want a simple definition first. If you add:

$webRoot = "";
$srvRoot = "";

before line 8, the notice goes away.

thanks the notice went away but when i echo WEB_ROOT it doesnt display value
but displays values when i echo $webRoot or $srvRoot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.