awsm awsm - 1 year ago 126
PHP Question

Remove plus sign (+) from string

I am trying to use

to remove a plus sign (
) from my string. I used

$variation = preg_replace('/[^\p{L}\p{N}\s]/u', '', $variation);

But that removed periods (
) too, which I need it in the string. Is there a way to just remove the plus sign?

Answer Source

Although the original answer to this question does achieve the intended effect, it is not the most efficient way to do this simple task. As noted in the comments above, the use of str_replace() is preferred in this case.

$variation = str_replace("+", "", $variation);


This works to remove only a plus sign:

$variation = preg_replace(/[+]/, "", $variation);

You can see it work here: (be sure you select the preg_replace function)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download