Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - XHTML linebreaks <br />

Tags:

php

xhtml

Here is the code:

if (isset($_POST['state']) && count($err) > 0) {
    echo "<p>";
    array_walk($err, create_function('&$value', 'printf("$value<br />");'));
    echo "<br /><a href=\"/#contacto\">Volver</a></p>";
}

The problem:

The code works as expected, but it insists on printing linebreaks like <br>. Refusing to print them like <br />, as if it didn't like the XHTML guidelines. Any other forward slash / (in a closing tag) is printed correctly.

I have already tried nl2br() with the second parameter set to 'true'. I've tried escaping them with a backslash \ (and then the backslash is printed but not the forward slash). I've tried escaping them with another forward slash (curiously enough it didn't comment the rest of the line), and passed the strings through echo, printf, and trim to no avail.

Can anyone tell me what is going on?

like image 450
Roman Porras Avatar asked Sep 26 '26 12:09

Roman Porras


1 Answers

To simplify your logic, you could just use:

echo implode('<br />', $err);

If you've tried all those techniques to no avail, are you sure there's an issue with your code? Maybe you should try viewing your code using another browser, or even with some command-line tool such as curl:

curl http://www.example.com/
like image 103
cmbuckley Avatar answered Sep 28 '26 02:09

cmbuckley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!