2019年12月25日 星期三

php xmlrpc decode bug for large size and solution

1. When the response is large than 10MB the xmlrpc decode will return null

https://www.php.net/manual/en/function.xmlrpc-decode.php

Note that from libxml 2.7.9+ there is a limit of 10MB for the XML-RPC response.

If the response is larger, xmlrpc_decode will simply return NULL.

There is currently no way to override this limit like we can with the other xml functions (LIBXML_PARSEHUGE)


2.  solution parse using the

SimpleXML


example:
<?php
        //Enter your code here, enjoy
    $xmlString = <<<EOF
<?xml version='1.0'?>
<methodResponse>
        <params>
            <param>
                <value>
                    <array>
                        <data>
                            <value>
                                <string>Hello</string>
                            </value>
                            <value>
                                <string>Andy</string>
                            </value>
                        </data>
                    </array>
                </value>
            </param>
        </params>
</methodResponse>
EOF;

$xml = new SimpleXMLElement($xmlString);

if ($xml===null || !is_object($xml))
    die('Failed to load xml file.');
    

echo "ok";    

//print_r($xml);
echo $xml->params->param->value->array->data->value->string;
echo $xml->params->param->value->array->data->value[1]->string;

2019年12月23日 星期一

php unicode to utf8

<?php
        //Enter your code here, enjoy!


print_r(json_decode('{"t":"\u00ed"}'));

$str = "\u9060\u50b3\u96fb\u4fe1";
echo unicode2utf8($str);

function unicode2utf8($str){
        if(!$str) return $str;
       
        $decode = json_decode($str);
        if($decode) return $decode;

        $str = '["' . $str . '"]';
        $decode = json_decode($str);
        if(count($decode) == 1){
                return $decode[0];
        }
        return $str;
}

2019年12月4日 星期三

C# all other

1. route

a. https://dotblogs.com.tw/brooke/2014/12/10/147597

b.https://medium.com/quick-code/routing-in-asp-net-core-c433bff3f1a4

c. https://dotblogs.com.tw/lastsecret/2010/02/27/13798


Reference
https://blog.johnwu.cc/categories/asp-net-core/

2019年12月2日 星期一

C# new class

1. code

using System;

public class HowToObjectInitializers
{
    public static void Main()
    {
        // Declare a StudentName by using the constructor that has two parameters.
        StudentName student1 = new StudentName("new1", "Playstead");

        // Make the same declaration by using an object initializer and sending
        // arguments for the first and last names. The default constructor is
        // invoked in processing this declaration, not the constructor that has
        // two parameters.
        StudentName student2 = new StudentName
        {
            FirstName = "new2",
            LastName = "Playstead",
        };

        // Declare a StudentName by using an object initializer and sending
        // an argument for only the ID property. No corresponding constructor is
        // necessary. Only the default constructor is used to process object
        // initializers.
        StudentName student3 = new StudentName
        {
            ID = 183
        };

        // Declare a StudentName by using an object initializer and sending
        // arguments for all three properties. No corresponding constructor is
        // defined in the class.
        StudentName student4 = new StudentName
        {
            FirstName = "new4",
            LastName = "Playstead",
            ID = 116
        };

        Console.WriteLine(student1.ToString());
        Console.WriteLine(student2.ToString());
        Console.WriteLine(student3.ToString());
        Console.WriteLine(student4.ToString());
    }
    // Output:
    // Craig  0
    // Craig  0
    //   183
    // Craig  116

    public class StudentName
    {
        // The default constructor has no parameters. The default constructor
        // is invoked in the processing of object initializers.
        // You can test this by changing the access modifier from public to
        // private. The declarations in Main that use object initializers will
        // fail.
        public StudentName() { }

        // The following constructor has parameters for two of the three
        // properties.
        public StudentName(string first, string last)
        {
            FirstName = first;
            LastName = last;
        }

        // Properties.
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int ID { get; set; }

        public override string ToString()
{
return FirstName + "  " + ID;
}
    }
}

2. Refrence
https://docs.microsoft.com/zh-tw/dotnet/csharp/programming-guide/classes-and-structs/how-to-initialize-objects-by-using-an-object-initializer


https://dotnetfiddle.net/

2019年12月1日 星期日

C# async/await

1. Expalin
https://blog.darkthread.net/blog/async-aspnet/


2. code
https://docs.microsoft.com/zh-tw/dotnet/csharp/language-reference/operators/await


---
using System;
using System.Net.Http;
using System.Threading.Tasks;

public class AwaitOperator
{
    public static async Task Main()
    {
        Task<int> downloading = DownloadDocsMainPageAsync();
        Console.WriteLine($"{nameof(Main)}: Launched downloading.....1\n");

        int bytesLoaded = await downloading;
        Console.WriteLine($"{nameof(Main)}: Downloaded {bytesLoaded} bytes.....4\n");

    }

    private static async Task<int> DownloadDocsMainPageAsync()
    {
        Console.WriteLine($"{nameof(DownloadDocsMainPageAsync)}: About to start downloading.....2\n");
     
        var client = new HttpClient();
        byte[] content = await client.GetByteArrayAsync("https://docs.microsoft.com/en-us/");
     
        Console.WriteLine($"{nameof(DownloadDocsMainPageAsync)}: Finished downloading.....3");
        return content.Length;
    }
}

---


3. online c#
https://dotnetfiddle.net/

dotnet fileter choose .netcore3.0


4.
https://stackoverflow.com/questions/19335451/async-and-await-are-not-working


5. Very goodd
https://www.huanlintalk.com/2016/01/async-and-await.html