Reputation: 348
I am new to php,there is a statement confused me.
<?php
$dom=new Document();
$dom->loadHTMLFile('http://php.net');
$xml = simplexml_import_dom($dom);
$nodes = $xml->xpath('//a[@href]');
foreach ($nodes as $node) {
echo $node['href'], "<br />\n";
}
?>
If we change echo $node['href'], "<br />\n";
into echo $node['href']."<br />";
,it has the same effect,same output in my web page,i want to know
What is the difference between echo "some string",<br />\n";
and echo
?
"some string".<br />";
Upvotes: 1
Views: 6805
Reputation: 614
<br />
is a HTML line-break, whereas \n
is a newline character in the source code.
In other words, <br />
will make a new line when you view the page as rendered HTML, whereas \n
will make a new line when you view the source code.
Alternatively, if you're outputting to a console rather than somewhere that will be rendered by a web browser then \n
will create a newline in the console output.
Upvotes: 3