VBA Excel MacOs. Cyrillian code for PHP server



  • I'm sending a GET request to the server, response to the line. It's working in a cupcake under the Wind. And in a cupcakes under MacOs, he's giving out the crados. But the capital letters break, the little ones get normal.

    PHP on server:

    <?php
    header( "Content-Type: text/html; charset=utf-8" ); 
    // charset=windows-1251 пробовал, utf-16, ISO разные, на эту строку вообще не реагирует
    $str = "ABCdef.АБВГД.абвгд";
    //перед выводом пробовал разные танцы с бубном, результаты такие:
    //echo $str;                                                //  ABCdef.–Р–С–Т–У–Ф.–∞–±–≤–≥–і
    //echo iconv('utf-8', 'windows-1251', $str);                //  ABCdef.јЅ¬√ƒ.абвгд
    echo mb_convert_encoding($str, "windows-1251", "utf-8" );   //  ABCdef.јЅ¬√ƒ.абвгд
    ?>
    

    VBA macroc:

    Option Explicit
    Private Declare PtrSafe Function popen Lib "/usr/lib/libc.dylib" (ByVal command As String, ByVal mode As String) As LongPtr
    Private Declare PtrSafe Function pclose Lib "/usr/lib/libc.dylib" (ByVal file As LongPtr) As Long
    Private Declare PtrSafe Function fread Lib "/usr/lib/libc.dylib" (ByVal outStr As String, ByVal size As LongPtr, ByVal items As LongPtr, ByVal stream As LongPtr) As Long
    Private Declare PtrSafe Function feof Lib "/usr/lib/libc.dylib" (ByVal file As LongPtr) As LongPtr
    

    #If Mac Then
    'макрос для Mac
    params = "test=test"
    result = HTTPGet("http://f0106330.xsph.ru/test.php", params)
    #Else
    'макрос для Win
    Set oHttp = CreateObject("MSXML2.ServerXMLHTTP")
    comp = CreateObject("WScript.Network").ComputerName
    sUrl = "http://f0106330.xsph.ru/test.php?test=test"
    oHttp.Open "GET", sUrl, False
    oHttp.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
    oHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    oHttp.Send ("")
    result = oHttp.ResponseText
    #End If

    Function HTTPGet(sUrl As String, sQuery As String) As String
    Dim sCmd As String
    Dim sResult As String
    Dim lExitCode As Long

    sCmd = "curl --get -d """ &amp; sQuery &amp; """" &amp; " " &amp; sUrl
    sResult = execShell(sCmd, lExitCode)
    HTTPGet = sResult
    

    End Function

    Function execShell(command As String, Optional ByRef exitCode As Long) As String
    Dim file As LongPtr
    file = popen(command, "r")

    If file = 0 Then
        Exit Function
    End If
    
    While feof(file) = 0
        Dim chunk As String
        Dim read As Long
        chunk = Space(50)
        read = fread(chunk, 1, Len(chunk) - 1, file)
        If read &gt; 0 Then
            chunk = Left$(chunk, read)
            execShell = execShell &amp; chunk
        End If
    Wend
    
    exitCode = pclose(file)
    

    End Function

    And if you do it, curl http://f0106330.xsph.ru/test.php in a terminal with a minimum code PHP on a server <?php $str = "ABCdef.АБВГД.абвгд"; echo $str;?>the result is normal.



  • It's a coding case, on a macque in VBA macroes. https://ru.wikipedia.org/wiki/MacCyrillic , it's a single-bite coding, and the Russian text here comes in a two-bite UTF-8.

    Like the letter бwith code in UTF-8 D0 B1♪ into MacCyrillic ♪ –± (sighs) That's it. D0± That's it. B1)

    Therefore, in the violin, we convert UTF-8 to MacCyrillic for macos, a parameter can be transferred for determination

    <?php
    $str = "ABCdef.АБВГД.абвгд";
    

    if ($_GET['os'] === 'macos') {
    echo iconv('utf-8', 'MacCyrillic', $str);
    } else {
    echo $str;
    }
    ?>

    Sub DoQuery()
    Dim result As String
    Dim params As String
    params = "os=macos"
    result = HTTPGet("http://192.168.64.3/test/test.php", params)
    Cells(1, 1).Value = result
    MsgBox result
    End Sub

    However, this decision only works for English and Cyrillic symbols, for example, it does not work for a line like that. ßååååå I couldn't come up with a universal solution.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2