PHP include - conditional

by 7 replies
11
Here's what I need to do... I just need someone to translate it into PHP:

If file 12345.txt exists, <?php include 'aaaaa.html'; ?>
If file 12345.txt does not exist, <?php include 'bbbbb.html'; ?>

What is the correct PHP syntax for this?

Thanks!
#programming #conditional #include #php
  • Banned
    Gene

    You should use the if/else statement

    Code:
    if (condition)
      code to be executed if condition is true;
    else
      code to be executed if condition is false;
  • Right, but that's what I'm asking for... the actual code needed. The correct syntax. Thanks.
  • $textfile="test123.txt";

    if (file_exists($textfile))
    { include "filename1.htm"; }
    else
    { include "filename2.htm"; }
    • [ 1 ] Thanks
  • Thank you Dylan! I'll try that out. Appreciate it!
  • Banned
    Sorry Gene - misunderstood - thought you wanted the syntax, not the actual code.

    Glad you got it sorted.

    Cheers.
    • [ 1 ] Thanks
    • [1] reply
    • Then it's my mistake... I used the word syntax thinking in terms of code... lol

      Thanks for your help
      • [1] reply

Next Topics on Trending Feed