|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16501 preg_replace() seems to act in strange with some escaped chars.
Submitted: 2002-04-08 17:32 UTC Modified: 2002-04-09 10:24 UTC
From: haug at berndhaug dot net Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 4.0.6 OS: SuSE GNU/Linux 7.3
Private report: No CVE-ID: None
 [2002-04-08 17:32 UTC] haug at berndhaug dot net
Was writing a script to replace single linebreaks in input to <br/> and multiple to </p><p class="content"> such as to parse user scribbling to very simple xhtml. Multiplatform linebreaks should be accepted.

There, I think I encountered very strange behaviour of PHP concerning octally escaped chars.

If I did something very very stupid, please don't hate me too much, I'm not too experienced w/ php. I however first showed this to a friend who is and he didn't know what it was either.

Short script:
// parsed all newlines as single ones, resulting in a many <br/>s --
// two (!) for a linebreak, 1 for every added linebreak in the input
parseUserTextfield1($input) {
	       array('<br/>','</p><p class="content">'),

  return $parsed;

// parsed all newlines as multi ones, resulting in a many </p><p>s --
// so, only the first one seems to be matched...almost as if one linebreak in
// the browser seemed like multiple ones in the string
// browser is a mozilla 0.9.8 on the server -- shouldn't it just send \012
// using a linux-based system?

parseUserTextfield2($input) {
		       array('</p><p class="content">','<br/>'),

  return $parsed;

// curious thing: if i replace the linebreak expr. w/ BREAK as in:
function parseUserTextfield($input) {
		       array('</p><p class="content">','<br/>'),

  return $parsed;
// everything works as expected

List of Modules // ./configure - line (this simply is the SuSE7.3 i386 Cfg with security updates):

'./configure' '--prefix=/usr/share' '--datadir=/usr/share/php' '--bindir=/usr/bin' '--libdir=/usr/share' '--with-config-file-path=/etc' '--with-exec-dir=/usr/lib/php/bin' '--with-mysql=/usr' '--with-gd=yes' '--enable-gd-native-ttf' '--enable-gd-imgstrttf' '--with-tiff-dir=/usr' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--with-xpm-dir=/usr/X11R6' '--with-ldap=yes' '--with-zlib=yes' '--with-bz2' '--with-gmp' '--with-xml' '--with-dom' '--with-ttf' '--with-t1lib' '--with-mcal=/usr' '--with-imap=yes' '--with-sablot' '--with-readline' '--with-ftp' '--with-ndbm' '--with-gdbm' '--with-mcrypt' '--with-gettext' '--with-mm' '--with-gd=yes' '--with-qtdom=/usr/lib/qt' '--enable-versioning' '--enable-yp' '--enable-bcmath' '--enable-trans-sid' '--enable-inline-optimization' '--enable-track-vars' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-shmop' '--enable-calendar' '--enable-mbstring' '--enable-mbstr-enc-trans' '--enable-exif' '--enable-ftp' '--enable-memory-limit' '--enable-wddx' '--enable-filepro' '--enable-dbase' '--enable-ctype' '--disable-debug' '--enable-force-cgi-redirect' '--enable-discard-path' '--enable-sigchild' '--with-openssl' '--with-curl' '--with-swf=./dist/' '--with-imap-ssl' '--with-gd=yes' '--with-apxs=/usr/sbin/apxs' '--with-pgsql=/usr' '--with-snmp' 'i386-suse-linux'

Other Info:
None that I know of.

No crash, no trace.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-09 04:17 UTC]
The bug system is not the appropriate forum for asking support
questions. For a list of a range of more appropriate places to ask
for help using PHP, please visit

Hint: IIRC, PHP converts all newlines to \n so you can use \n in your regexes.
 [2002-04-09 10:24 UTC] haug at berndhaug dot net
My stupid: Windows linebreak ist \015\012, so curious things were bound to happen.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 04 14:01:28 2023 UTC