[php] What does <? php echo ("<pre>"); ..... echo("</pre>"); ?> mean?

The question is the tag <pre> </pre>

I've seen one script I am working on, uses it:

echo ("<pre>");

.... ....

echo ("</pre>");

What exactly does it do ?

Is it an Html tag or a PHP ?

I've searched on Google but nothing much comes out of it. When do we usually use that HTML tag?...or PHP tag?

This question is related to php html

The answer is


The <prev>-tag might be an XML-tag.


The PHP function echo() prints out its input to the web server response.

echo("Hello World!");

prints out Hello World! to the web server response.

echo("<prev>");

prints out the tag to the web server response.

echo do not require valid HTML tags. You can use PHP to print XML, images, excel, HTML and so on.

<prev> is not a HTML tag. Is is a valid XML tag, but since I don't know what page you are working in, i cannot tell you what it is. Maybe it is the root tag of a XML page, or a miswritten <pre> tag.


It is nor php nor html it sounds like specific xml tag.


try this:

$names = array('Jesse', 'joey', 'jelnny', 'justine');
$names = new ArrayObject($names);

echo '<pre>';
print_r($names);

vs this:

$names = array('Jesse', 'joey', 'jelnny', 'justine');
$names = new ArrayObject($names);

//echo '<pre>';
print_r($names);

and it shows what the PRE does very neatly


"<pre>" is an HTML tag. If you insert this line of code in your program

echo "<pre>";

then you will enable the viewing of multiple spaces and line endings. Without this, all \n, \r and other end line characters wouldn't have any effect in the browser and wherever you had more than 1 space in the code, the output would be shortened to only 1 space. That's the default HTML. In that case only with <br> you would be able to break the line and go to the next one.

For example,

the code below would be displayed on multiple lines, due to \n line ending specifier.

<?php
    echo "<pre>";
    printf("<span style='color:#%X%X%X'>Hello</span>\n", 65, 127, 245);
    printf("Goodbye");
?>

However the following code, would be displayed in one line only (line endings are disregarded).

<?php
    printf("<span style='color:#%X%X%X'>Hello</span>\n", 65, 127, 245);
    printf("Goodbye");
?>

if you put text within an HTML tag, all spaces and line breaks will be preserved.

Otherwise, the default behaviour is to remove multiple spaces and keep only one space, and ignore line breaks (unless you use the
tag).

I'd like to say it's from the time before CSS - not necessarily used to make text more legible, only more formatted.


$testArray = [
[
  "name"   => "Dinesh Madusanka",
  "gender" => "male"
],
[
  "name"   => "Tharaka Devinda",
  "gender" => "male"
],
[
  "name"   => "Dumidu Ranasinghearachchi",
  "gender" => "male"
]


 ];

  print_r($testArray);

  echo "<pre>";
  print_r($testArray);

The <pre> is used to define pre-formatted text.
The text within <pre> tag is displayed in a fixed-width font and it preserves both spaces and line breaks that are present in the text.
Here I'm printing a JSON FILE without <pre> tag and then with <pre> tag.

Without <pre> tag
https://i.stack.imgur.com/ofRn8.jpg
With <pre> tag
https://i.stack.imgur.com/XzDVg.jpg


I think you're talking about <pre></pre>. element is displayed in a fixed-width font, and it preserves both spaces and line breaks.

try printing an array with a **<pre>** and whitout **<pre>**

$arr = array(1, 2, 3);

echo '<pre>';
print_r($arr);
echo '</pre>';

print_r($arr); 

here whatever we write in between the pre tags it will be interpreted same as html pre tag

ex:

<?php
echo '<pre>';
echo '
code here 
will be displayed
as it 
is 


namaste
';
echo "this line get printed in new line";
echo "</pre>";
echo "Now pre ended:";
echo "this line gets joined to above line";
?>

and content b/w 's font also changes.


echo (""); is a php code, and <prev> tries to be HTML, but isn't.

As @pekka said, its probably supposed to be <pre>