Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4129
  • Last Modified:

replace comma with space

Hi,
how do i replace a comma, a carrage return, new line, a tab into a blank space all in once.

str_replace and preg_replace.?

str_replace works for only one.  i have

$Comments = str_replace(",", "", $row_orders_status_history["comments"]);
0
tgatif
Asked:
tgatif
1 Solution
 
tgatifAuthor Commented:
fixed with the function.
function filter_text($text) {
$filter_array = array(",", "\r", "\n");
return str_replace($filter_array,"",$text);
}
0
 
sdmdjCommented:
The above example didn't include tab removal, here is the updated version along with example/usage code:

<?php
$my_text="This is my text, there is a comma,\rblah blah\nblah blah\ttabbed in here\tand here\n";

function replace_chars($input)
{
      $filter=array(",","\r","\n","\t");
      
      return str_replace($filter,"",$input);
}

print replace_chars($my_text);
?>
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now