1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Trying to get PHP code to recognize musical notes

Discussion in 'PHP' started by Darden12, Oct 30, 2020.

  1. #1
    I am trying to use functions like substr_count and strpos to find the number and location of musical notes in text, specifically the musical note that looks like this ... ♪ ...which I believe is an eighth note. I can't get this to work consistently in my PHP code. For example:

    In some of my PHP scripts, the following line will tell me how many musical notes are in $myText...
    $j=substr_count($myText,'♪')
    ...yet in other of my PHP scripts, the same line does not work for me.

    I think I need to be declaring a decoding type to get this to work correctly, but I haven't identified what that is. I thought the secret was the meta tag I've pasted below, but I've added it to the beginning of my latest PHP script and the above code still does not work. Any suggestions on how I can get PHP to always recognize musical notes as musical notes? (Right now it's recognizing the note as a hashtag, judging by the ord value that it returns for the note character.)

    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
     
    Darden12, Oct 30, 2020 IP
  2. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #2
    Try using utf8_encode, something like this:

    $j=substr_count( utf8_encode($myText), utf8_encode('♪'));

    see if it works then.

    By the way, meta tags do not affect PHP. Those are for browsers, to tell what character encoding to use to display the webpage.
     
    JEET, Nov 4, 2020 IP