Remove characters from a string

I'm writing my first object oriented script that spells triads and chords derived from the major, harmonic minor or jazz minor.

I need to remove the characters  ♭ ♯ 𝄪  𝄫 from a note.

So I need to remove the ♯ from D♯ and return a D.

What is the best way to do this?
burnedfacelessAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
Probably several ways to do it. Loops / Regex / Trimming.

Maybe the simplest is to not 'remove' specific characters, but to only leave specific character, either base on a collection of 'alloweds' or even easier - just return the first character:

var note = "D♯";
var baseNote = note[0];

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
I might have misunderstood the requirement but can't you do a str_replace on the char you want to replace? If you need to remove multiple chars then preg_replace
<?php
$source = "D♯A♭B𝄪C♯EF𝄫G";
$result = preg_replace('[♭|♯|𝄪|𝄫]', '', $source);
echo $result;

Open in new window

0
aboo_sCommented:
$str = preg_replace("/[^A-Za-z0-9?! ]/","",$str);
this will allow only letters numbers and spaces in your string
0
Chris StanyonWebDevCommented:
Oops - for some reason, I read this as a C# question - not a PHP one. Here's the PHP version of it:

$note = "D♯";
$baseNote = $note[0];

Open in new window

0
burnedfacelessAuthor Commented:
It's cool man I was in C# before I was suspended when marijuana was found in my dorm. I knew what you were saying I was smoking more marijuana instead of coding.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.