PHP include - conditional

7 replies
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!
#conditional #include #php
  • Profile picture of the author pjCheviot
    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;
    {{ DiscussionBoard.errors[832257].message }}
  • Profile picture of the author Gene Pimentel
    Right, but that's what I'm asking for... the actual code needed. The correct syntax. Thanks.
    {{ DiscussionBoard.errors[832277].message }}
  • Profile picture of the author Dylan W
    $textfile="test123.txt";

    if (file_exists($textfile))
    { include "filename1.htm"; }
    else
    { include "filename2.htm"; }
    {{ DiscussionBoard.errors[832483].message }}
  • Profile picture of the author Gene Pimentel
    Thank you Dylan! I'll try that out. Appreciate it!
    {{ DiscussionBoard.errors[832522].message }}
  • Profile picture of the author pjCheviot
    Banned
    Sorry Gene - misunderstood - thought you wanted the syntax, not the actual code.

    Glad you got it sorted.

    Cheers.
    {{ DiscussionBoard.errors[832603].message }}
    • Profile picture of the author Gene Pimentel
      Originally Posted by pjCheviot View Post

      Sorry Gene - misunderstood - thought you wanted the syntax, not the actual code.

      Glad you got it sorted.

      Cheers.
      Then it's my mistake... I used the word syntax thinking in terms of code... lol

      Thanks for your help
      {{ DiscussionBoard.errors[832684].message }}
      • Profile picture of the author pjCheviot
        Banned
        Originally Posted by Gene Pimentel View Post

        Then it's my mistake... I used the word syntax thinking in terms of code... lol

        Thanks for your help
        LOL - I should have shown the code too, so I think we both got confused Sorry!
        {{ DiscussionBoard.errors[832823].message }}

Trending Topics