PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Text » Text_Highlighter » Bug #3106

diff Highlighter produces to many newlines

Details

Submitted2005-01-05 13:26 UTC
Fromwebmaster at phpmyforum dot de
StatusNo Feedback
PackageText_Highlighter
PHP Version5.0.3
OSLinux
Roadmaps(Not assigned)

Comments

[2005-01-05 13:26 UTC] webmaster at phpmyforum dot de

Description:
------------
The diff Highlighter produces to many newslines with the following Source.

After these line the Parser adds an newline, but he shouldn't:

138a118,119

Reproduce code:
---------------
71,91d70
config['INDEX_BIRTHDAYS']) && !empty($_stat['birthdays'])) {
query('SELECT u.`id`, u.`name`, YEAR(u.`geb`) AS `year`, g.`wio_color`
fetch_array($result)) {
'.(($geb['wio_color']) ? ''.$geb['name'].'' : $geb['name']).''.(($geb['year'] != 0) ? ' ('.($year-$geb['year']).')' : '');
0) ? implode(', ', $liste) : '';
### neue Zeilen
>
141c122

\ Kein Zeilenumbruch am Dateiende.
---
> ?>

Expected result:
----------------
71,91d70
< ### birthdays
< $birthday_list = '';
< if (!empty($_pmf->config['INDEX_BIRTHDAYS']) && !empty($_stat['birthdays'])) {
< $liste = array();

< $year = date('Y');
< $result = $_db->query('SELECT u.`id`, u.`name`, YEAR(u.`geb`) AS `year`, g.`wio_color`
< FROM `'.$_cfg['DB_PREFIX'].'user` AS u,
< `'.$_cfg['DB_PREFIX'].'group` AS g
< WHERE u.`id` IN ('.$_stat['birthdays'].')
< AND g.`id` = u.`group_id`

< GROUP BY u.`id`
< ORDER BY u.`name`');
< while ($geb = $_db->fetch_array($result)) {
< $liste[] = '<a href="profile.php?id='.$geb['id'].'&amp;'.$_sess['url'].'">'.(($geb['wio_color']) ? '<span style="'.$geb['wio_color'].'">'.$geb['name'].'</span>' : $geb['name']).'</a>'.(($geb['year'] != 0) ? ' ('.($year-$geb['year']).')' : '');

< }
< $birthday_list = (count($liste) > 0) ? implode(', ', $liste) : '';
< }
<
<
< #
< #

138a118,119
> ### neue Zeilen
>
141c122
< ?>
\ Kein Zeilenumbruch am Dateiende.
---
> ?>

Actual result:
--------------
71,91d70
< ### birthdays
< $birthday_list = '';
< if (!empty($_pmf->config['INDEX_BIRTHDAYS']) && !empty($_stat['birthdays'])) {
< $liste = array();

< $year = date('Y');
< $result = $_db->query('SELECT u.`id`, u.`name`, YEAR(u.`geb`) AS `year`, g.`wio_color`
< FROM `'.$_cfg['DB_PREFIX'].'user` AS u,
< `'.$_cfg['DB_PREFIX'].'group` AS g
< WHERE u.`id` IN ('.$_stat['birthdays'].')
< AND g.`id` = u.`group_id`

< GROUP BY u.`id`
< ORDER BY u.`name`');
< while ($geb = $_db->fetch_array($result)) {
< $liste[] = '<a href="profile.php?id='.$geb['id'].'&amp;'.$_sess['url'].'">'.(($geb['wio_color']) ? '<span style="'.$geb['wio_color'].'">'.$geb['name'].'</span>' : $geb['name']).'</a>'.(($geb['year'] != 0) ? ' ('.($year-$geb['year']).')' : '');

< }
< $birthday_list = (count($liste) > 0) ? implode(', ', $liste) : '';
< }
<
<
< #
< #
138a118,119
> ### neue Zeilen
>
141c122
< ?>
\ Kein Zeilenumbruch am Dateiende.
---
> ?>

[2005-01-15 13:50 UTC] webmaster at phpmyforum dot de

I've found the problem, it's the \r within the code.

So you only have to use str_replace to remove \r within the highligting code.

Works fine for me :)

[2005-02-01 17:27 UTC] webmaster at phpmyforum dot de

no it's the normal Windows-like \r\n

you can use this, to fix it:

$string = preg_replace('#\r?\n#', "\n", $string);

Greets