473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Firefox/Explorer problem

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
4 1186
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
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
Thanks.
Feeling extremely stupid for missing that now...

Jul 5 '06 #4
*** 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Geoff | last post by:
When trying to focus a field in Firefox, I get the following error: Error: " nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame ::...
2
by: Chuck Martin | last post by:
I am having a most frustrating problem that references, web searches, and other resources are no help so far in solving. Basically, I'm trying to design a pop-up window to be called with a funciton...
14
by: catorcio | last post by:
I'm trying to have some text in my page changed by clicking a button. Googleing around I've discovered that innerText doesn't work with every browser, so I've switched to innerHTML. It works fine...
5
by: Prophet | last post by:
Might be a stupid question...... but I keep seeing people post about firefox. What is firefox?
3
by: Jim | last post by:
I had Firefox set as my default browser, but I wanted to change back to IE when testing my webservices. Easy enough....(in IE) Tools>Internet Options>Programs then check "Internet Explorer...
11
by: minnesotti | last post by:
Hi there, I subscribed to a photographic pictures-hosting website which is heavy on JavaScript. My preferred latest browser Mozilla Firefox does not work with it -- no pictures are displayed and...
28
by: entfred | last post by:
I have the following line of html: &nbsp;&nbsp1234&nbsp;&nbsp;&nbsp;&nbsp;&nbspabc&nbsp;&nbsp;&nbspyow In Internet Explorer 6.0, the columns look ok using the above html: 1234 abcd ...
8
by: golfchick | last post by:
Well im at the end of my teather, ive been searching for an answer to no avail. Ive used suggested html and css checkers both say my code is perfect and yet there seems to be a distinct difference...
1
by: shidhincr | last post by:
I have some doubts regarding XML and XSL transfornation using javascript.Hope SomeOne will help me for solving this problem. Actually i Created a javascript for transforming XML and XSL. i made...
5
by: sheldonlg | last post by:
I am top-posting this one time because this in new stuff and I am leaving the bottom for reference and description of the problem. I am also adding comp.lang.php as this is all done in php and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.