php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28886 line breaks in textareas forces preg_replace to quit
Submitted: 2004-06-23 04:40 UTC Modified: 2004-06-24 02:42 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: slunta at msn dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4.3.6 OS: Linux
Private report: No CVE-ID: None
 [2004-06-23 04:40 UTC] slunta at msn dot com
Description:
------------
I don't know why, or how, but it appears that a line break in a textarea will cause a preg_replace to quit. Let me show you the code and the page so you can test it and see for yourself what I'm talking about.

You can find the page with the code at:

http://turkeybot.olddh.com/bug.php

Reproduce code:
---------------
<?

$message=isset($_POST['message']) ? htmlentities($_POST['message']) :'';

$array1=array('/&lt;b&gt;(.+)&lt;\/b&gt;/','/&lt;i&gt;(.+)&lt;\/i&gt;/','/&lt;u&gt;(.+)&lt;\/u&gt;/');
$array2=array('<b>$1</b>','<i>$1</i>','<u>$1</u>');
$mess=preg_replace($array1,$array2,$message);

echo '<html>
<form action="bug.php" method="post">
' .$mess. '
<textarea name="message" cols="40" rows="10"></textarea>
<input type="submit" name="post" value="Post" /><input type="reset" name="reset" value="Reset" /></form>';

?>

Expected result:
----------------
When I post the data, I always expect to see my <b>,<i>,and<u> tags to run correctly and display the message with the proper html.

Actual result:
--------------
The preg_replace fails in replacing the entities with the proper tags once a line break is inserted into the textarea.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-23 04:43 UTC] slunta at msn dot com
It's either \n or <br /> causing this issue: I am not sure.
 [2004-06-24 02:42 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You need to specify a parameter that will tell preg_* not 
to stop at a new line. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 12:01:32 2024 UTC