-1

How can i delete a html-special char \ from a string.

$string = 'This is \ a string with \ special characters \';
Raymond van Os
  • 191
  • 1
  • 5
  • 18

5 Answers5

1
str_replace("char_to_rep","",$string); // replacing with nothing means deleting 


also ref. how-to-remove-html-special-chars

Community
  • 1
  • 1
Bhavin Rana
  • 1,554
  • 4
  • 20
  • 40
0

use str_replace and replace special char with an empty character

akjoshi
  • 15,374
  • 13
  • 103
  • 121
SHAKIR SHABBIR
  • 1,295
  • 1
  • 14
  • 25
0
str_replace("#"," ",$string)

try this code for all special char

Naresh Tank
  • 1,569
  • 10
  • 23
0

thanks a lot for help, but is there a better way tho do this below?

    $post = '(&repl^eac&e_+';

    function repleace($post) {
        $array = array('.html', '.php', '±', '§', '!', '@', '€', '`', '#', '$', '%', '^', '&', '*', '(', ')', '+', '=', '<', '>', '?', '/', '|', '[', ']', ':', ';', ',', '~', '.');
        $post = str_replace($array, '', $post);
        $post = str_replace(' ', '_', $post);
        $post = str_replace('-', '_', $post);
        return strtolower('/'.$post.'/');
    }
Raymond van Os
  • 191
  • 1
  • 5
  • 18
0
function($input) {
   $input = preg_replace("/&#?[a-z0-9]{2,8};/i","",$input);
   $input = ucfirst($input);
   return $input;
}

The php pre_repleace function within the /&#?[a-z0-9]{2,8};/i characters works fine.

Raymond van Os
  • 191
  • 1
  • 5
  • 18