Jump to content

Removing unsafe characters from a string?


Switch0r

Recommended Posts

You can use preg_raplace like so:
[code]<?php

$string = "This \"string\" has; : got some 'unsafe' chars!";
$string2 = preg_replace("([;:\"'])", "", $string);

echo $string2;

?>[/code]
Or you can use str_replace like so:
[code]<?php

$string = "This \"string\" has; : got some 'unsafe' chars!";

$string2 = str_replace(array(";", ":", "\"", "'"), "", $string);

echo $string2;

?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.