技術情報

Handling Japanese characters in PHP

We know we have manipulate strings, characters in PHP using various function depending on what we need. For example – cutting strings, counting strings length, replacing strings etc. We can directly use built-in PHP function like substr, str_replace, str_length etc. But we can’t directly use these functions for Japanese characters, Why ?

Everyone knows that a “bit” is 0 or 1, nothing else, and a “byte” is a group of eight consecutive bits. Since one byte has eight of these dual value points, the byte can consist of a total of 256 different patterns (2 power 8). Different characters can be associated with each possible 8-bit pattern.

It is working fine as long as the language characters can be represented by 256 or less.

But what if you can’t represent a language with just 256 characters? Obviously Japanese characters need more than that. Nowadays , 256 characters isn’t enough anywhere. Fortunately, the new super character sets use anywhere from 1 to 4 bytes to define characters. Unicode, a scheme that uses multiple bytes to represent characters. There are several version of it like UTF-32, 26 8.

Unicode (including UTF-8) uses multiple byte configurations to represent characters. UTF-8 uses 1 to 4 bytes to generate 1,112,064 patterns that represent different characters.

We can’t still directly use string related functions by declaring UTF-8. PHP isn’t really designed to handle multibyte characters, so using standard string functions to handle these characters can have uncertain results. If you need to handle these multibyte characters, you need to use a special set of functions, the mbstring function. Use the --enable-mbstring compile-time option to enable the mb function and set the run-time configuration option mbstring-encoding_translation.

The next thing is HTTP header might covers the communication also contains the character set ID, so we need to declare the header also like this.

mb_internal_encoding("UTF-8");

Finally we can use mb string related function instead of directly using string function.

For example we can use mb_strlen instead of strlen .

You can see various mb functions here.

That’s all for today.

Yuuma



Flutter – share option button

This week I would like to share you about how to add share option button in flutter. Let’s get started!

First thing we need to do is to add this share pub in your pubspec.yaml file.

dependencies:
  share: ^2.0.4
We can simply apply the share pub in the code.
return Scaffold(
      appBar: AppBar(
        title : const Text('Share option '),
        actions: [
          Padding(padding: const EdgeInsets.all(10),
            child: IconButton(
              icon : const Icon(Icons.share_outlined),
              onPressed: () {
                Share.share("https://dummy~~~~~~~.com");

              },
            )
          )
        ],
      ),
    );

Hope you enjoyed this article!

By Ami



Flutter – Clipboard

This week also let’s learn flutter new things. I will show you how to copy and paste a text with flutter. Let’s start coding.

First thing we need to do is add this clipboard package in pubspec.yaml file.

flutter pub add clipboard

Copy to clipboard

FlutterClipboard.copy(field.text).then(( value ) => print('copied'));

Paste from clipboard

FlutterClipboard.paste().then((value) {
    // Do what ever you want with the value.
    setState(() {
      field.text = value;
      pasteValue = value;
    });
  });

For text editing field :

TextEditingController field = TextEditingController();
TextFormField(
                controller: field,
                decoration: const InputDecoration(
                    hintText: 'Enter text'
                ),
              ),

Hope you enjoyed this article!

By ami



Flutter – Scrollbar

This week I would like to share about scrollbar widget and how to use it. Let’s go and start code!

By default scrollbar widget in flutter don’t show a scrollbar. But that’s fine in many cases but in others, you do want to display a scrollbar. Scrollbars show the users how far they’ve scrolled, and they allow things like jumping to a particular point in the list.

To show scrollbar use the widget called Scrollbar!

Make sure the scrollbar widget is finite. For example, it’s a ListView.builder, make sure itemCount is defined.

return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Scrollbar(
            child: ListView.builder(
              itemCount: 20,
              itemBuilder: (context, index) {
                return Card(
                  child : ListTile(
                    title: Text("Item: ${index + 1}"),
                  )
                );
              }
            )
          ),
        )
      )
    );

Hoped you enjoyed this article!

By Ami



Switch List Tile in flutter

Take a moment to think back to the last time you looked at the settings page. If you wish you would quickly and easily create a list of toggle switches like that, just use SwitchListTile.

Switch List Tile, you get a little tile that’s tappable anywhere to switch a toggle from off to on.

SwitchListTitles API looks a lot like widgets of similar names. ListTile, CheckboxListTile, RadioListTile, SwitchListTile all follow the same pattern.

ListTile(
 title: Text("List Tile"),
),
SwitchListTile(
 title: Text("Switch List Tile"),
/*.....*/
),

Start with the title : Text, which will appear in the middle of the tile. Then you can add Icons to either end, and with the control tiles like SwitchListTile.

ListTile(
 title: Text("List Tile"),
 leading: Icon(Icons.ac_unit),
 trailing: Fire(),
),
SwitchListTile(
 title: Text("Switch List Tile"),
 secondary: Icon(Icons.ac_unit),
 
),

Hope you enjoyed this article!

By Ami




アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム