Jump to content

Text Parsing Ie8 Problem


tal
 Share

Recommended Posts

hello i have a problem with text parsing when i write this html+css code in a html file it works finebut when i write it in a php file i see a different result the two lines become one and without multi white spaces but only in IE8 (in FF3 it works fine)also when i look at the source code from the browser (right click options)i see the text parsed as it should be (with line breaks and multi spaces)please help me understand what is going on replace the ------------ with spaces as this form cuts them out

<div style="white-space:pre-wrap;">first line of wordsnext line-------------------and some more after many spaces</div>

Link to comment
Share on other sites

I don't think IE8 understands white-space:pre-wrap. For maximum compatibility, why don't you convert the newlines to break tags and the spaces to non-breaking ones?

Link to comment
Share on other sites

i have added </br> to where there was \r beforebut how do i create non-breaking spaces ?here is a discription of what i am doing the user writes in a textarea formthis code gets what he wrote

$write_text=$_POST['write_text'];if (strlen($write_text)>0)	{	str_replace("\r","\r</br>",$write_text);	$write_text=$writer_name.": ".$write_text."</br>\r----------------------------</br>";	$im=fopen ($file_name,"a+");	fwrite ($im,"$write_text\r");        }

and this is how i display it - reading it from the file

<div style="white-space:pre-wrap;"><?php echo $file ?></div>

now the problem remains in the display of what the user wrote while looking at it in IE8if he writes two lines of text, it will show as one even when i do str_replace("\r",'\r</br>',$write_text);the </br> tags are not writen to the filewhen i look at the source code both IE8 and FF3 from the browser (right click) options i do see the </br> tags i added, they are in their place but it doesn't show when i look at the page

Edited by tal
Link to comment
Share on other sites

str_replace does not act directly on the string you pass it. You need to grab the return value. Something like:$write_text = str_replace("\r","\r<br />",$write_text);Be sure too that a carriage return is the only character your source text might use as a line break. Different operating systems use different characters. Example 1 here has an item (it's about sixth from the top) that can do the trick: http://us2.php.net/manual/en/function.str-replace.phpEDIT. Use the correct tag. For HTML, it's <br> . For XHTML, the slash is at the end: <br />

Edited by Deirdre's Dad
Link to comment
Share on other sites

You can also just use nl2br() for newlines. A non-breaking space is represented by the entity  .

Edited by Synook
Link to comment
Share on other sites

good it worksso i added $write_text=nl2br($write_text,false);insted of my $write_text = str_replace("\r","\r<br />",$write_text);and took out the cssstyle="white-space:pre-wrap;"so now i am doing a manual "white-space" but it shows in both IE8 and FF3 as i want it to, with line breaks (i am giving multi-spaces a second thought)thank you very much for helping Synook and Deirdre's DadTal

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...