ari_aaron Posted December 29, 2006 Share Posted December 29, 2006 Is there a way to print a newline? It's been a while since I used PHP, but I seem to remember that doing it before.I don't mean a HTML newline, but in the source code, to make it easy to read.Any help? Quote Link to comment https://forums.phpfreaks.com/topic/32205-newline/ Share on other sites More sharing options...
ted_chou12 Posted December 29, 2006 Share Posted December 29, 2006 but new line do you mean >>> \r\n ?Ted Quote Link to comment https://forums.phpfreaks.com/topic/32205-newline/#findComment-149473 Share on other sites More sharing options...
dbo Posted December 29, 2006 Share Posted December 29, 2006 echo "Somestuff\n"; Quote Link to comment https://forums.phpfreaks.com/topic/32205-newline/#findComment-149474 Share on other sites More sharing options...
ari_aaron Posted December 29, 2006 Author Share Posted December 29, 2006 Sorry, that works, but it dosn't do what I expenected. I am trying to output a javascript, like this:[code]/*****************REPORT PMs*************//*Report PMs to Admin©2006 by ari_aaron*/adminname="ari_aaron"if (location.href.match("&fwd=1&report=1")){subj=document.getElementsByName('msg_title')[0].value.replace("Fwd:"," ")rep = document.getElementById('userlinks').getElementsByTagName('A')[0].innerHTMLdocument.getElementsByName('entered_name')[0].value=adminnamedocument.getElementsByName('msg_title')[0].value="Reported PM"omess=document.getElementsByName('Post')[0].valuemess=omess.replace("[QUOTE]Message Forwarded From", "[b]Sender:[/b]")mess=mess.replace("\n","\n[b]Reporter:[/b] "+rep+"\n[b]Subject:[/b] "+subj+" \n [b]Message[/b]:\n[QUOTE]")document.getElementsByName('Post')[0].value=messdocument.getElementsByName("submit")[0].click()}if(location.href.match("act=Msg&CODE=03")){divs=document.getElementsByTagName('div')for(i=0;i!=divs.length;i++){if(divs[i].innerHTML.match(">Forward PM<")){path=divs[i].getElementsByTagName('a')[0].href+"&report=1"divs[i].innerHTML=divs[i].innerHTML.replace(']', '| <a href='+path+'>Report PM</a>]')}}}/*************END CODE******************/[/code]It is much easier to read with newlines. I thought a newline in the source code would make a newline here, but it seems that I was wrong.Is it the file type? Or is there a way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/32205-newline/#findComment-149494 Share on other sites More sharing options...
kenrbnsn Posted December 29, 2006 Share Posted December 29, 2006 Please post the PHP script that is used to produce the Javascript.Ken Quote Link to comment https://forums.phpfreaks.com/topic/32205-newline/#findComment-149497 Share on other sites More sharing options...
ari_aaron Posted December 29, 2006 Author Share Posted December 29, 2006 It's not really the code, it is selected from the SQL database where it has newlines, and they are displayed as '\n'. I was asking before for outputting the comments on top which is just echoing a line with inserted info: [code]echo '/***'.$codename.'***/';[/code]This is more complicated than I thought. Quote Link to comment https://forums.phpfreaks.com/topic/32205-newline/#findComment-149512 Share on other sites More sharing options...
wildteen88 Posted December 29, 2006 Share Posted December 29, 2006 When echo'ing lines with whitespace characters (\t, \n, \r etc) do not use single quotes. PHP will treat these literaly. PHP will ignore their special meaning. Instead you should use double quotes:wont work:[code=php:0]echo 'this \n string \n has \n new lines!';// output: this \n string \n has \n new lines![/code]Will work:[code=php:0]echo "this \n string \n has \n new lines!";/* output: this string has new lines! */[/code]NOTE: You will only see these newlines when viewing the source code in the browser. The browser ignores these characters. In order for the browser to show the new lines you will need to convert them to HTML linebreaks ([nobbc]<br />[/nobbc] Quote Link to comment https://forums.phpfreaks.com/topic/32205-newline/#findComment-149541 Share on other sites More sharing options...
ari_aaron Posted December 31, 2006 Author Share Posted December 31, 2006 [quote]NOTE: You will only see these newlines when viewing the source code in the browser. The browser ignores these characters. In order for the browser to show the new lines you will need to convert them to HTML linebreaks (<br />[/quote]That won't help me then.Is there a way I can get the browser to show it as if it was a JS page, and still execute PHP? Quote Link to comment https://forums.phpfreaks.com/topic/32205-newline/#findComment-150489 Share on other sites More sharing options...
wildteen88 Posted December 31, 2006 Share Posted December 31, 2006 I am confused what are you trying to do. The browser will only ignore the whitespace when you go to view the page. However the whitespace will be present when you go to view the source (right click > view source). Quote Link to comment https://forums.phpfreaks.com/topic/32205-newline/#findComment-150507 Share on other sites More sharing options...
ari_aaron Posted December 31, 2006 Author Share Posted December 31, 2006 Please read the rest of the topic where I explained it. I am trying to output a javascript page and I want to make it easy to read. Quote Link to comment https://forums.phpfreaks.com/topic/32205-newline/#findComment-150517 Share on other sites More sharing options...
wildteen88 Posted December 31, 2006 Share Posted December 31, 2006 I still don't get what you want to do. Sorry. Are you wanting to show the actual javascript code in the browser or in the source code? Quote Link to comment https://forums.phpfreaks.com/topic/32205-newline/#findComment-150540 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.