php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #23253 highlight_string($string) removes newlines from input string
Submitted: 2003-04-17 02:06 UTC Modified: 2017-10-24 02:00 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: gk at proliberty dot com Assigned: kalle (profile)
Status: Closed Package: *General Issues
PHP Version: master OS: *
Private report: No CVE-ID: None
 [2003-04-17 02:06 UTC] gk at proliberty dot com
If you use highlight_string() to produce HTML formatted source, the output string replaces newlines with <br \>.

This is very ugly and unnecessary. 
Whitespace is an important part of code; readability is not an insignificant feature.
Instead, "\n" should be replaced with "<br \>\n", or "<br>\n", to be HTML compliant.

<?php
// $source_file includes line breaks
$source=join('',file($source_file));
$body=highlight_string ( $source, $return=TRUE);
// $body is a single line, without line breaks
?>

Patches

clarify_highlight_string_output.patch (last revision 2013-12-24 21:17 UTC by aaron dot hamid at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-31 05:56 UTC] yohgaki@php.net
-Status: Open +Status: Verified -Package: Feature/Change Request +Package: *General Issues -Operating System: linux +Operating System: * -PHP Version: 4.3.2RC1 +PHP Version: master
 [2013-07-31 05:56 UTC] yohgaki@php.net
Current PHP doesn't add linefeed as reporter said. However, we do not have to 
change behavior as highlighted source is for browsers, not human. 

Left this report open, in case someone would like to change behavior.
 [2013-12-24 20:37 UTC] aaron dot hamid at gmail dot com
So at the least this warrants a documentation update right?
 [2013-12-24 21:19 UTC] aaron dot hamid at gmail dot com
I submitted the attached patch to php doc system for review.

How would one go about introducing a minor enhancement as described - just a pull request?  The change is trivial and I don't think it would have any BC implications.
 [2017-10-24 02:00 UTC] kalle@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: kalle
 [2017-10-24 02:00 UTC] kalle@php.net
The documentation for this was fixed, I believe the main reason for why this was never fixed or changed was that highlighted code was intended for <pre> HTML tags.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 18:01:30 2024 UTC