1

How would I get:

print (!$getTemplate) ? "Cannot Find Template File!" : "Template OK!";

to be used as:

if (!$getTemplate)
{
    echo "Cannot Find Template File!";
}
else
{
    echo "Template OK!";
};

I have tried so many way of doing it but cant find it, im still quite new at PHP.

2
  • There is a semicolon ; at the end of the if statement. I didn't remove it while editing assuming that you might have put it intentionally. It should be removed. Commented Apr 19, 2012 at 14:38
  • Just tested and even with the semicolon removed it still doesn't work. Commented Apr 19, 2012 at 14:40

3 Answers 3

1

It's hard to tell where this going wrong from your question but I would suggest this.

You could try using file_exists();

For example:

Edited later to include OP's edit:

$getTemplate = '/path/to/file.html';

if ( ! file_exists($getTemplate))
{
    echo "Cannot Find Template File!";
}
else
{
    echo "Template OK!";
    // fopen, fwrite, fclose here
}
Sign up to request clarification or add additional context in comments.

4 Comments

I have already created the file dynamically, this is just to check if it is in the folder and the writes the string to a file.
Yes this code will check if it is in a folder, you would then add your writing to a file code to the else portion of above code.
Thanks! My day must have been to long. This works fine! i just have to clean it up.
:-) glad to have helped, accepting my answer would be much appreciated.
1

you mean like this:

 echo (!$getTemplate ? "Cannot Find Template File!" : "Template OK!");

1 Comment

Ye i saw that and fixed it, i used print originally.
1

You can just pass that first expression you listed to the echo construct:

echo ( $getTemplate ? "Template OK!" : "Cannot find template file!" );

(Note: I removed the ! and reversed the order of the ternary arguments to make it easier to follow.)

1 Comment

I need to eventually write the text to a file and cant get fwrite to work in that string.

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.