0

Not much to explain really, I just cant figure out the correct syntax to use a variable in an include URL

heres what I thought it would be:

$round_num=1;
include '../../fixtures/round{$round_num}fix.php';

It returns the usual:

Warning: include(../../fixtures/round{$round_num}fix.php) [function.include]: failed to open stream: No such file or directory

This must be a very simple one for allot of you out there lol but i just cant find my answer ANYWHERE!

2 Answers 2

3

Use double quotes (") to delimit your string. String interpolation doesn't occur in single quoted (') strings.

$round_num=1;
include "../../fixtures/round{$round_num}fix.php";
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much! so i have to use double quotes whenever i want to use a variable in something like this?
@ProdigyDoo Or concatenation.
0

you can also use alternate syntax such as:

include "../../fixtures/round" . $round_num . "fix.php";

Sometimes people prefer to have the variable highlighted by their IDE for clarity.

2 Comments

Personally I don't see the point of using double quotes and escaping the variable.
I usually don't do this;however, it's very common.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.