Jump to content

Newline


ari_aaron

Recommended Posts

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].innerHTML
document.getElementsByName('entered_name')[0].value=adminname
document.getElementsByName('msg_title')[0].value="Reported PM"
omess=document.getElementsByName('Post')[0].value
mess=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=mess
document.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?
Link to comment
https://forums.phpfreaks.com/topic/32205-newline/#findComment-149494
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/32205-newline/#findComment-149512
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/32205-newline/#findComment-149541
Share on other sites

[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?
Link to comment
https://forums.phpfreaks.com/topic/32205-newline/#findComment-150489
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.