4

I have a variable in PHP like Logo™. How do I remove the character , if it's present?

3 Answers 3

3

Since it seems like you're getting data from an outside source, perhaps it might be better to filter out all characters you aren't expecting. What this will include will vary depending on what the variable is for. For example, if you're expecting it to be a single simple word, you could remove anything which isn't a letter.

$str = preg_replace("/[^a-zA-Z]/", "", $str);

Just be careful to think about what is and isn't allowed. The above code would remove accented characters, for example.

Sign up to request clarification or add additional context in comments.

Comments

3

$str = str_replace(chr(153), '', 'Logo™');

1 Comment

php.net/str_replace Replace all occurrences of the search string with the replacement string, in this example char with ascii-code 153 (™) will be replace to empty ('').
0
$str = 'Logo™';
$str = substr_replace('™', '', $str); // Logo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.