Extra \r\n using include() on wamp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cwjacklin
    New Member
    • Mar 2009
    • 4

    Extra \r\n using include() on wamp

    Hi all,
    I use WAMP server 2, php 5.2.8
    This code
    [code=php]
    echo "1";
    include(mnmincl ude.'html1.php' );
    echo "2";
    [/code]
    prints out "1\r\n2" even though there are only functions in html1.php file but no echo statement.

    When run on a linux server, there are no extra "\r\n". I assume this is wamp/apache behavior and not php behavior. How do people who develop on WAMP and deploy on Linux deal with these types of string issues?

    Thanks,

    Jack
    Last edited by pbmods; Mar 2 '09, 11:52 PM. Reason: Fixed CODE tags.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    I imagine there is something inside that file that is outputting the carriage return and new line characters. Can we see what's in there?

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      note:though it is not required, it is always good practice to write constants in upper case, makes them easy to identify.

      Comment

      • cwjacklin
        New Member
        • Mar 2009
        • 4

        #4
        Thanks. Code looks like this. The extra CRLF after the closing <?php> code... <?> is the source of the problem.
        I wonder why this is only a problem in WAMP but not on Linux. Further, I would think there would need to be explicit echo calls to output to responsetext, rather than just random \r\n at the end of the included files.

        Code:
                      url = $thisurl + '/checkfield.php?type='+type+'&name=' + field.value;
                      checkitxmlhttp = new myXMLHttpRequest ();
                      checkitxmlhttp.open ("GET", url, true);
                      checkitxmlhttp.onreadystatechange = function () {
                              if (checkitxmlhttp.readyState == 4) {
                              responsestring = checkitxmlhttp.responseText;
        Code:
               
              //checkfield.php -------------------------------------
              include_once('Smarty.class.php');
              $main_smarty = new Smarty;
              echo "1";
              include('config.php');
              echo "2";
              include(mnminclude.'html1.php');
              echo "3";
        //output --------------------------------------------
        "1\r\n\r\n2\r\n 3"

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Originally posted by cwjacklin
          I wonder why this is only a problem in WAMP but not on Linux.
          It could be anything from the way the operating-systems handles files to the way your PHP editor saves files. (Some of them trim trailing white-spaces, some don't).

          It's best just to make sure there is no room for misinterpretati on by not leaving white-spaces where they shouldn't be.

          Originally posted by cwjacklin
          Further, I would think there would need to be explicit echo calls to output to responsetext, rather than just random \r\n at the end of the included files.
          Anything outside <?php ?> tags is usually considered HTML by Apache and added to the output accordingly.
          Consider this:
          [code=php]
          <html>
          <head><title>Te st</tile></head>
          <body>
          <table>
          <?php
          for($i = 0; $i < 5; ++$i) {
          echo "<tr>";
          for($j = 0; $j < 5; ++$j) {
          echo "<td>", pow($j, $i), "</td>";
          }
          echo "</tr>";
          }
          ?>
          </table>
          </body>
          </html>[/code]
          If nothing unless the echo statements made it to the output, this type of syntax could not be used.

          And keep in mind that a HTML infused PHP code like that is often included. In fact, I'm pretty sure the Smarty template engine does a lot of that.

          Comment

          • cwjacklin
            New Member
            • Mar 2009
            • 4

            #6
            Well, the issue is say I have some code that expects well formatted XML. And then I add a module which has extra \r\n in the php file. Now those \r\n makes the XML un-parse-able. It's possible to catch this, but not a pretty solution, especially if you don't have control over 3rd party modules.

            I have searched around, I am surprised that I haven't found other people with this issue.

            Comment

            Working...