-2

I'm quite new to PHP. I have created an array which I have included however when I need to echo a url which is in my settings array it just gives me the following error:

Parse error: syntax error, unexpected 'templateurl' (T_STRING) in C:\xampp\htdocs\index.php on line 15

Thanks for your help and time in advance.

Maulik Savaliya
  • 1,262
  • 7
  • 17
Duncan McClean
  • 130
  • 2
  • 11

1 Answers1

0

Try this:

<?php include('hi.php'); echo $settings['templateurl'];?>

You need to include the file first and then you are able to retrieve the data from it.

J. Doe
  • 32
  • 5
  • Thanks. What would I do if I wanted to get two things from the array? `include('echo $settings['templateurl']echo $template['templateheader']');` Where templateheader is the path of a file. – Duncan McClean Feb 25 '17 at 10:52
  • Don't make the same mistake as above. Look at the code I have given you and read. Do the include first and then you can use the other variables inside. As per your example: If the header is the path just do – J. Doe Feb 25 '17 at 10:54
  • I have decided not to have the file names in the array. However, when I use this method. I seem to get around 5000 PHP errors. I think it is looking for the files in the same directory as the index.php is in. I'm so confused. – Duncan McClean Feb 25 '17 at 11:07
  • You need to specify where the file is located. e.g. and if it's just a variable I have added the quote only between the text and when it starts with $ it's without single quotes. – J. Doe Feb 25 '17 at 11:08
  • The file path is in the templateurl part. The file I need to include from that path is hi.php – Duncan McClean Feb 25 '17 at 11:10
  • Then it would be – J. Doe Feb 25 '17 at 11:11
  • Thanks. I've got it working :) – Duncan McClean Feb 25 '17 at 11:22