By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,530 Members | 891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,530 IT Pros & Developers. It's quick & easy.

Firefox/Explorer problem

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

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

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

echo preg_replace($search, $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_contents('text.txt');
$search = array("@\r\n@si");

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

echo preg_replace($search, $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

Jul 5 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Dan Pearce wrote:
Processing some text from an external text file into a web page. If I
use this:

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

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

echo preg_replace($search, $replace, $s);
?>
Shouldn't that be either:
$replace = array('<br />');
or
$replace = array('<br>');

-david-

Jul 5 '06 #2

P: n/a
Rik
Dan Pearce wrote:
Processing some text from an external text file into a web page. If I
use this:

<?
$s = file_get_contents('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($search, $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
Jul 5 '06 #3

P: n/a
Thanks.
Feeling extremely stupid for missing that now...

Jul 5 '06 #4

P: n/a
*** 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
--
Jul 5 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.