0

I am essentially trying to combine to PHP statements.

<?php echo ROOT_PATH; ?>
<?php echo file_get_contents( "../css/themes/subtitle.php"); ?>

I want to achieve something like this:

<?php echo file_get_contents( "ROOT_PATH/css/themes/subtitle.php"); ?> 
stevland
  • 119
  • 1
  • 8

3 Answers3

2

If you call constants inside single or double quotes then it will be always picked as a string.

You need to add like below:

<?php echo file_get_contents( ROOT_PATH."/css/themes/subtitle.php"); ?> 
Amit Gupta
  • 2,771
  • 2
  • 17
  • 31
  • That looks like what I am after, but it isn't working. – stevland Dec 28 '17 at 07:01
  • Check first ROOT_PATH is having correct path. Try like echo ROOT_PATH; die; – Amit Gupta Dec 28 '17 at 07:02
  • You correctly defined ROOT_PATH or not and correct path must be there. You can print your complete path first to check if it is correct or not. – Amit Gupta Dec 28 '17 at 07:03
  • I can confirm ROOT_PATH is working, for example both of the two statements I posted produce the results I expect. – stevland Dec 28 '17 at 07:04
  • ROOT_PATH must be having ".." only then the path will be like ../css/themes/subtitle.php – Amit Gupta Dec 28 '17 at 07:06
  • I am new to PHP, obviously. But I am well familiar with UNIX file paths and I experimented with a few variations. I'm not sure why I couldn't get this to work but I thank you for your time. – stevland Dec 28 '17 at 07:13
0

. operator is used to concatenating.

Like:

$str = "Hello";
echo $str;
echo "World";

can be written as

$str = "Hello";
echo $str."World";
Siraj Alam
  • 9,217
  • 9
  • 53
  • 65
  • I can see that your answer is essentially what Mahesh Hegde did in the answer that I marked as correct. As I am new to PHP I couldn't really look at what you posted and see the result I was after. I'm not there yet. But thanks for taking the time to post. – stevland Dec 28 '17 at 07:17
  • I gave you the general solution which is also applicable to your question. – Siraj Alam Dec 28 '17 at 07:27
0

Its pretty simple you can change it to following

//full path of the file 
$file_name = ROOT_PATH."/css/themes/subtitle.php";
echo file_get_contents($file_name);

it should work

Mahesh Hegde
  • 1,131
  • 10
  • 12