Firefox/Explorer problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan Pearce

    Firefox/Explorer problem

    Processing some text from an external text file into a web page. If I
    use this:

    <?
    $s = file_get_conten ts('text.txt');
    $search = array("@\r\n@si ");

    $replace = array('</br>');

    echo preg_replace($s earch, $replace, $s);
    ?>

    Explorer shows the text as it appears in the file;

    This is some test text
    This is some test text

    This is some test text
    This is some test text

    but Firefox displays

    This is some test textThis is some test textThis is some test textThis
    is some test text

    Now if I use

    <?
    $s = file_get_conten ts('text.txt');
    $search = array("@\r\n@si ");

    $replace = array('<br></br>');

    echo preg_replace($s earch, $replace, $s);
    ?>

    The firefox output is correct but Explorer now double spaces everything

    This is some test text

    This is some test text



    This is some test text

    This is some test text

    Any ideas on how to correct this? Thanks in advance for your time.

    Dan

  • David Haynes

    #2
    Re: Firefox/Explorer problem

    Dan Pearce wrote:
    Processing some text from an external text file into a web page. If I
    use this:
    >
    <?
    $s = file_get_conten ts('text.txt');
    $search = array("@\r\n@si ");
    >
    $replace = array('</br>');
    >
    echo preg_replace($s earch, $replace, $s);
    ?>
    Shouldn't that be either:
    $replace = array('<br />');
    or
    $replace = array('<br>');

    -david-

    Comment

    • Rik

      #3
      Re: Firefox/Explorer problem

      Dan Pearce wrote:
      Processing some text from an external text file into a web page. If I
      use this:
      >
      <?
      $s = file_get_conten ts('text.txt');
      $search = array("@\r\n@si ");
      >
      $replace = array('</br>');
      Here's you problem already:
      It should be '<br />' in XHTML, '<br>' in HTML.
      echo preg_replace($s earch, $replace, $s);
      >>
      >
      Explorer shows the text as it appears in the file;
      Apparantly MSIE forgives your mistake and chooses to interpret '</br>' as
      '<br>'. FF correctly interprets it as a bogus tag and tries to ignore it.

      Why not use the function nl2br() though?
      Or, if you have a text-file with preformatted text, use the HTML <pretag.

      Grtz,
      --
      Rik Wasmus


      Comment

      • Dan Pearce

        #4
        Re: Firefox/Explorer problem

        Thanks.
        Feeling extremely stupid for missing that now...

        Comment

        • Alvaro G. Vicario

          #5
          Re: Firefox/Explorer problem

          *** Dan Pearce escribió/wrote (5 Jul 2006 06:57:45 -0700):
          Explorer shows the text as it appears in the file;
          >
          This is some test text
          This is some test text
          >
          This is some test text
          This is some test text
          >
          but Firefox displays
          >
          This is some test textThis is some test textThis is some test textThis
          is some test text
          You must be aware that the look of what either browser will render
          dependents strictly on two things:

          - The source code
          - The MIME type

          Alright, PHP can alter both of them, but the first step would be checking
          the "View-Source" menu



          --
          -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
          ++ Mi sitio sobre programación web: http://bits.demogracia.com
          +- Mi web de humor con rayos UVA: http://www.demogracia.com
          --

          Comment

          Working...