Link to home
Start Free TrialLog in
Avatar of burnedfaceless
burnedfaceless

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of Anwar Saiah
Anwar Saiah

$str = preg_replace("/[^A-Za-z0-9?! ]/","",$str);
this will allow only letters numbers and spaces in your string
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

Avatar of burnedfaceless

ASKER

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.