Bug #16501: preg_replace() seems to act in strange with some escaped chars.

From: Date: Mon, 08 Apr 2002 21:32:43 +0000
Subject: Bug #16501: preg_replace() seems to act in strange with some escaped chars.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-4375@lists.php.net to get a copy of this message
From: haug@berndhaug.net Operating system: SuSE GNU/Linux 7.3 PHP version: 4.0.6 PHP Bug Type: PCRE related Bug description: preg_replace() seems to act in strange with some escaped chars. Preface: 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) { $parsed=preg_replace(array("/(\012\015|\012|\015)/","/(\012\015|\012|\015)(\012\015|\012|\015)+/"), array('<br/>','</p><p class="content">'), $input); 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) { $parsed=preg_replace(array("/(\012\015|\012|\015)(\012\015|\012|\015)+/","/(\012\015|\012|\015)/"), array('</p><p class="content">','<br/>'), $input); return $parsed; } // curious thing: if i replace the linebreak expr. w/ BREAK as in: function parseUserTextfield($input) { $parsed=preg_replace(array("/(BREAK)(BREAK)+/","/(BREAK)/"), array('</p><p class="content">','<br/>'), $parsed); 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. Backtrace: No crash, no trace. -- Edit bug report at http://bugs.php.net/?id=16501&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=16501&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=16501&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=16501&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=16501&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=16501&r=support Expected behavior: http://bugs.php.net/fix.php?id=16501&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=16501&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=16501&r=submittedtwice

« previous php.bugs (#4375) next »