How shall I define a base directory with predefined path variable?

//Path variable
$path = "sub-directory";

If I define the directory in the following way

define('BASE_DIR','/home/user/public_html/directory/$path/'); 

It returns,

string(8) "BASE_DIR" string(39) "/home/user/public_html/directory/$path/" 

But it should return

string(8) "BASE_DIR" string(47) "/home/user/public_html/directory/sub-directory/"

When I echo or dump it.

What's going wrong?

    Single quoted string do not interpolate variables. You need to use a double quoted string in your define call.

      I wish double quote could extract the variable in url path.

      Thanks,

        polarexpress;11041303 wrote:

        I wish double quote could extract the variable in url path.

        Thanks,

        It does ... do we misunderstand your question?

        define('BASE_DIR',"/home/user/public_html/directory/$path/");
          dalecosp;11041307 wrote:

          It does ... do we misunderstand your question?

          define('BASE_DIR',"/home/user/public_html/directory/$path/");

          Yes, double quote in the above code works fine.

          Though a directory is a part of url path, may be I could ask the question the other way like,

          "Extracting variable in url path"

          Anyway, the problem has been resolved finally with your assistance.

          Thanks,

            Write a Reply...