Write .txt extension for $filename

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gobblegob
    New Member
    • Dec 2007
    • 133

    Write .txt extension for $filename

    Hi guys,

    i am trying to add .txt extension to the filename.

    Code:
    $filename    = (isset($_POST['filename']))    ? $_POST['filename']    : '' ;
    Thanks in advanced.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    what’s the problem?

    Comment

    • nouras
      New Member
      • Apr 2010
      • 15

      #3
      you can use dot to add any string to the variable
      like this

      Code:
      $filename=$_POST['filename'];
      $filename.="txt";
      OR
      Code:
      $filename=$_POST['filename']."txt";

      Comment

      • gobblegob
        New Member
        • Dec 2007
        • 133

        #4
        Originally posted by nouras
        you can use dot to add any string to the variable
        like this

        Code:
        $filename=$_post['filename'];
        $filename.="txt";
        OR
        Code:
        $filename=$_post['filename']."txt";
        Thanks Nouras, you are a champion!

        i got it with this :)
        Code:
                $filename    = (isset($_POST['filename']))    ? $_POST['filename']    : '' ;
                $filename    = $filename.=".txt";

        Comment

        • nouras
          New Member
          • Apr 2010
          • 15

          #5
          you are welcome :)

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            *gg* why so complicated?
            Code:
            $filename = (isset($_POST['filename'])) ? $_POST['filename'] . ".txt" : NULL;

            Comment

            • gobblegob
              New Member
              • Dec 2007
              • 133

              #7
              Originally posted by Dormilich
              *gg* why so complicated?
              Code:
              $filename = (isset($_POST['filename'])) ? $_POST['filename'] . ".txt" : NULL;
              Yeah that works too, Thanks.

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Originally posted by nouras
                you can use dot to add any string to the variable
                like this

                Code:
                $filename=$_post['filename'];
                $filename.="txt";
                OR
                Code:
                $filename=$_post['filename']."txt";
                Variables are not case-insensitive in PHP. $_post should be $_POST.

                Comment

                • nouras
                  New Member
                  • Apr 2010
                  • 15

                  #9
                  Originally posted by Markus
                  Variables are not case-insensitive in PHP. $_post should be $_POST.
                  sure .....
                  thanx,your eyes also case-sensitive :)

                  Comment

                  Working...