简体   繁体   中英

how to remove \r\n\r\n from an textarea using php

I am not able to remove these "\\r\\n\\r\\n" from textarea using any of below method

Good job overall!\r\n\r\n*********************************************************************** \r\n\r\nSoft skills: Please don\'t forget to ask customers for the reason of cancellation.

在此处输入图片说明

methods 
$resolution = trim($resolution);

//Effort 2
$resolution = nl2br($resolution);

//Effort 3
$resolution = htmlentities($resolution);

//Effort 4
$resolution = preg_replace("\\r\\n","<br>",$resolution);

$snip = str_replace("\t", '', $snip); // remove tabs
$snip = str_replace("\n", '', $snip); // remove new lines
$snip = str_replace("\r", '', $snip); // remove carriage returns

Array

( [0] => Array ( [field_id] => 5497 [type] => F [parent_id] => 0 [field_type] => selectbox [field_name] => Retention Offered? [required] => 1 [maxlength] => 0 [field_value] => YES [not_applicable] => on )

[1] => Array
    (
        [field_id] => 5494
        [type] => F
        [parent_id] => 0
        [field_type] => textarea
        [field_name] => Summary of Interaction
        [required] => 1
        [maxlength] => 0
        [field_value] => Cx requested cancel, agent secured and explained account, offered rates, cx declined, agent confirmed cancellation
        [not_applicable] => on
    )

[2] => Array
    (
        [field_id] => 5495
        [type] => F
        [parent_id] => 0
        [field_type] => textarea
        [field_name] => Feedback
        [required] => 0
        [maxlength] => 0
        [field_value] => Good job overall!\r\n\r\n*********************************************************************** \r\n\r\nSoft skills: Please don\'t forget to ask customers for the reason of cancellation.
        [not_applicable] => on
    )

)

user preg_replace , To remove \\n\\r from a string, follow the below code

$title = "Good job overall!\r\n\r\n*********************************************************************** \r\n\r\nSoft skills: Please don't forget to ask customers for the reason of cancellation";
$new_title = preg_replace("/[\n\r]/","",$title); 
echo $new_title;

DOME

I done this using below code , ( '\\t', '\\n', '\\r' ) just used single quotes instead of double quotes

$snip = str_replace('\t', '', $snip); // remove tabs
$snip = str_replace('\n', '', $snip); // remove new lines
$snip = str_replace('\r', '', $snip); // remove carriage returns

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM