05 สิงหาคม 2554

It's important inforsci@blogger.com

inforsci@blogger.com,

How had you been??? Hows every thing going?

Anyway, I am sooooo happy right now;-))

I am glad because of http://tiny.cc/gvj13

It may work for you as well.

I think you should check this out seriously.


Cheers,

08 พฤศจิกายน 2553

Howto setup MRTG

Installing MRTG and adding additional Data Sources on Windows

by usernamedenied on April 7, 2009

This guide explains how to  install MRTG on Windows and monitor different signals like memory and network usage.

MRTG is a software used to monitor different "signals" and display them in nice graphs.

I will use Windows XP as Operating System but it also works on Windows Server 2003.

Download MRTG

I will install mrtg-2.16.2 which can be downloaded here, however you should install the latest version which can be found here.

After downloading it, unpack it to where you want, I will use the following path:C:\mrtg-2.16.2

Install Perl

To run MRTG we need to install Perl first, I would recommend installing ActivePerl which can be found here.

It is pretty simple to install Perl so I won't cover it, just follow the Setup.

Setting up the SNMP Service

Browse to Control Panel  Add or Remove Programs  Add / Remove Windows Components and then select Management and Monitoring Tools and then click Next.

You will probably be requested to insert the Windows CD to copy the required files.

After installing it, we need to configure it.

Browse to Control Panel  Administrative Tools  Services and then find the Service called SNMP Service, double-click on it and then select the Traps tab.

In the Community name textbox, write public and then click the button Add to list.

Now switch to the Security tab.

Add public to the Accepted community names with the READ ONLY community right.

Then select Accept SNMP packets from these hosts and add 127.0.0.1 to the list.

We have successfully configured SNMP on our Windows machine.

Install MRTG

Now we need access to a Command Prompt. Click Start  Run and then insert cmdand press enter.

In my case I have extracted the MRTG files to the following path: C:\mrtg-2.16.2

cd C:\mrtg-2.16.2\bin

Now we are going to create our MRTG configuration file, the WorkDir is the Path to where you want the files to be written, for example the public folder of your webserver.

perl cfgmaker public@127.0.0.1 –global "WorkDir: c:\xampp\htdocs\mrtg" –output mrtg.cfg

If it doesn't output anything, then it means it worked.

perl indexmaker –output index.html mrtg.cfg

This will create an html file with the layout. Now copy that index.html file into your WorkDir (in my case c:\xampp\htdocs\mrtg)

copy index.html c:\xampp\htdocs\mrtg

Don't forget to replace c:\xampp\htdocs\mrtg with your WorkDir!

Run MRTG

We still need a command-prompt. Execute the following commands

cd C:\mrtg-2.16.2\bin

perl mrtg mrtg.cfg

You have now manually triggered mrtg to get the data and draw it into the graphs.

Now we need to make this run automatically as it would be quite annoying if you had to manually run this command every 5 minutes..

Open your mrtg.cfg with a texteditor and add the line RunAsDaemon: yes

Now execute perl mrtg mrtg.cfg once again, MRTG has been started as a daemon, this is quite annoying because the command-prompt has to stay open. You can also create a Windows Service (Click here for additional informations)

Add Memory Usage and other Data sources

First we need to configure the inbuilt Performance Log of Windows. Click on Control Panel  Admistrative Tools  Performance  Performance Logs and Alerts then selectCounter Logs, then right-click on the blank window and select New Log Settings.

performance

Now we are going to create a new log, insert a name you want to use and then clickOK.

A Counter is only one log, like the memory usage and an object is a collection of informations on memory for example.

Click the button Add Counters or Add Objects.

I am going to add a Counter for this example.

Select Use local Computer counters then select Memory in the Performance Objectlist then select Avaible MBytes and click Add then Close.

avaible_mbytes

Then select the Log Files tab.

Select Text File(Comma delimited) in the Log file type listbox and then click OK.

log_file_type

Our .csv file is located at C:\PerfLogs\

We are now going to configure a .cfg file in MRTG to parse the .csv file which is created by the Windows Log Tool.

Please note that this script is a little bit buggy and the final results needs some tweaking, such as setting the MaxByte value in the graphs etc. The script has been written by castellan.net

Download the script here. If the link is broken download the mkcfg.vbs script hereand the getlog.pl script here (Don't forget to name the script getlog.pl)

We need a command-prompt.  Execute the following commands:

cd C:\mrtg-2.16.2\bin

cscript mkcfg.vbs c:\perflogs\memory.csv memory

This should create 2 files, .html and .cfg.

This is a little bit tricky, the mkcfg.vbs script is a little bit bugy, it repeats the last diagram a couple of times, so open up the memory.cfg with a text-editor and locate the duplicate diagrams. (Should be easy to spot)

After you deleted them, you need to change the WorkDir.

Copy the created .html file into your public mrtg folder and then execute this

perl mrtg memory.cfg

You have created a new graph display for your .csv file! (Don't forget to update this .cfg file too, refer to Run MRTG for more help)

If the legend isn't big enough, change MaxBytes in the .cfg file.

You can also include memory.cfg into mrtg.cfg . Add the following line into mrt.cfg

Include: memory.cfg

Indexmaker

Doesn't it annoy you that you have to visit 2 links to admire your graphs? Indexmaker can bind them together into one page.

perl indexmaker –output index.html mrtg.cfg memory.cfg

This command will bind both mrtg.cfg and memory.cfg into one file, named index.html. Now copy the index.html file into your WorkDir. That's it. If you want to see detailed informations about a graph, click on it.

Finally

You might want to rename your legends and titles to make the graphs more readable.

I hope this quick guide was somewhat useful, if you have any questions, feel free to post a comment.

Thanks for reading and good luck.




Best Regards,
ISCI(ART)

 


07 เมษายน 2553

2Complement Calculator

2Complement Calculator

¤èÒä´éÁÒ¡¡ÇèÒËÃ×Íà·èҡѺ 32768 à»ç¹¤èҵԴź
x >= 32768 à»ç¹¤èÒ -

x < 32768 à»ç¹¤èÒ +

Example
¤èÒź
65437-65536

¤èҺǡäÁèµéͧ·ÓÍÐäà (< 32768)

2Complement Calculator

 

ค่าได้มากกว่าหรือเท่ากับ 32768  เป็นค่าติดลบ

x >= 32768  เป็นค่า -

 

x < 32768  เป็นค่า +

 

Example

ค่าลบ

65437-65536

 

ค่าบวกไม่ต้องทำอะไร (< 32768)

 

 

 

05 ธันวาคม 2552

Hotmail สนับสนุน POP3 ทั้งหมด 100% แล้ว

เมื่อต้นปี ไมโครซอฟท์ได้เริ่มเปิดบริการ POP3 ของ Hotmail ให้กับผู้ใช้ในบางประเทศ มาถึงเมื่อวานนี้ ไมโครซอฟท์ได้ประกาศว่าผู้ใช้ Hotmail ทุกคนสามารถใช้งาน POP3 ได้แล้วครับ
สำหรับผู้ที่ต้องการใช้ Hotmail POP3 ต้องใส่ค่าตามนี้
  • POP server: pop3.live.com (Port 995)
  • POP SSL required? Yes
  • User name: Your Windows Live ID, for example yourname@hotmail.com
  • Password: The password you usually use to sign in to Hotmail or Windows Live
  • SMTP server: smtp.live.com (Port 25 or 587)
  • Authentication required? Yes (this matches your POP username and password)
  • TLS/SSL required? Yes
ผมทดสอบแล้วบน Evolution ก็พบว่าใช้งานได้ ส่วน IMAP นั้นยังไม่สนับสนุน
ที่มา - Windows Live Hotmail Blog, Ars Technica



Best Regards,
ISCI(ART)


     089-509-1528


14 ตุลาคม 2552

Auto refresh webpage but maintain scroll position รีเฟรช โดยที่สกอร์อยู่ที่เดิม

Auto refresh webpage but maintain scroll position

 
Sample 01
< html>
< title>< /title>
< head>
< script language="javascript">
 
// function saves scroll position
function fScroll(val)
{
    var hidScroll = document.getElementById('hidScroll');
    hidScroll.value = val.scrollTop;
}
 
// function moves scroll position to saved value
function fScrollMove(what)
{
    var hidScroll = document.getElementById('hidScroll');
    document.getElementById(what).scrollTop = hidScroll.value;
}
< /script>
< /head>
 
< body onload="fScrollMove('div_scroll');" onunload="document.forms(0).submit()";>
< form>
< input type="text" id="hidScroll" name="a">< /br>
< div id="div_scroll" onscroll="fScroll(this);" 
style="overflow:auto;height:100px;width:100px;">
 
.. VERY LONG TEXT GOES HERE
   
< /div>
< /form>
< /body>
< /html>

 

Edited By Tanakorn inuse

                <script language="JavaScript">

                        /*Maintaining Page Scroll Position

                        By Tanakorn Kulhong

                        Amptron

                        */

            setTimeout ("refreshPage()", 1000);        

            var scrollX = 0;

            var scrollY = 0; 

            function refreshPage() {

                        //var page = window.frames['mainFrame'];            

                        var page = window.parent.frames['mainFrame'];

                        scrollX = page.document.body.scrollLeft;

                        scrollY = page.document.body.scrollTop;

                        page.document.location = "realtimedata.php";

                        setTimeout("doScroll()", 50);//Time to maintain scroll millsec

            }

 

            function doScroll() {

                        //var page = window.frames['mainFrame'];

                        var page = window.parent.frames['mainFrame'];

                        page.document.body.scrollLeft = scrollX;

                        page.document.body.scrollTop = scrollY;

                        setTimeout ("refreshPage()", 1000);

            }

</script>

 

 

 

Sample 3

 

Here is the complete PHP example:

<HTML>

<HEAD>

<TITLE>Test</TITLE>

<script>

function SaveScrollXY() {

document.Form1.ScrollX.value = document.body.scrollLeft;

document.Form1.ScrollY.value = document.body.scrollTop;

}

function ResetScrollPosition() {

var hidx, hidy;

hidx = document.Form1.ScrollX;

hidy = document.Form1.ScrollY;

if (typeof hidx != 'undefined' && typeof hidy != 'undefined') {

window.scrollTo(hidx.value, hidy.value);

}

}

</script>

</HEAD>

<BODY onload="ResetScrollPosition()">

<form name="Form1″ id="Form1″ method="post"

onsubmit="SaveScrollXY()" action="index.php">

<input name="ScrollX" id="ScrollX" type="hidden"

value="<?php echo $_REQUEST['ScrollX'] ?>" />

<input name="ScrollY" id="ScrollY" type="hidden"

value="<?php echo $_REQUEST['ScrollY'] ?>" />

<p>This is just a paragraph to make a very long page.</p>

<P>This is just a paragraph to make a very long page.</P>

<P>

<input name="TextBox1″ type="text"

value="<?php $v = $_REQUEST['TextBox1']; echo $v ? $v + 1 : 1 ?>"

readonly="readonly" id="TextBox1″ /></P>

<P>

<input type="submit" name="Button1″ value="Post Form"

id="Button1″ /></P>

</form>

</BODY>

</HTML>

 

09 สิงหาคม 2552

Send data from PHP to flash

Send data from PHP to flash

จาก Entry ที่แล้ว เป็นการส่งข้อมูลจาก flash -> PHP
คราวนี้มาดูในทางกลับกัน คือส่งจาก PHP ไปยัง flash

วิธีการก็คือ ทาง PHP จะ echo string ที่อยู่ในรูปแบบ variable=value ไปให้ (ดู code ด้านล่าง)

code ใน PHP


<?php
echo"myVariable=Hello World";
?>


code ใน flash


//สร้าง textfield
this.createTextField("display_txt",1,0,0,100,20);
var hello_lv:LoadVars = new LoadVars();
//เมื่อ hello_lv ได้รับ ข้อมูลมา
hello_lv.onLoad = function(success){
if(success){
//นำ Hello World มาโชว์ใน text field
display_txt.text = this.myVariable;
}else{
trace("An error has occurred.");
}
}
//ให้ hello_lv โหลดข้อมูลจาก ไฟล์ php
hello_lv.load("sendtoflash.php");



ถ้าต้องการส่งหลายตัวก็ ส่งเป็น String "variable1=value1&variable2=value2&..."

 

Send data from flash to PHP by POST method

Send data from flash to PHP by POST method

เวลาที่จะต้องการส่ง ตัวแปร จาก flash ไปยัง PHP ก็จะทำโดยการนำตัวแปรทั้งหมด ยัดเข้าไปใส่ object ตัวนึง แล้วก็ส่งไป ทาง PHP ก็จะรับ โดย $_POST

ตัวอย่างที่ทำคือ ปุ่มกด ส่งค่าไปยัง php เพื่อ write ลง text file

code ใน flash

//สร้าง label
this.createClassObject(mx.controls.Label,"lb",4);
lb.move(20,0);
lb.autoSize = true;
lb.text = "press the button";

//สร้าง button
this.createClassObject(mx.controls.Button,"ok_bt",5,{label:"Send Data"});
ok_bt.move(20,20);

//สร้าง event เมื่อกด ปุ่มให้เรียก sendData()
var ok_listener:Object = new Object();
ok_listener.click = function(){
sendData();
}
ok_bt.addEventListener("click",ok_listener);


function sendData():Void{

var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function() {
lb.text = "Text file was written.";
};

var send_lv:LoadVars = new LoadVars();
//ยัดค่าของตัวแปร name และ website ลงไปใน send_lv
send_lv.name = "flashas";
send_lv.website = "http://flashas.exteen.com";
//ส่ง ตัวแปร name และ website ที่อยู่ใน send_lv ไปยัง print.php เมื่อเสร็จแล้วก็จะกลับมา call result_lv.onLoad
send_lv.sendAndLoad("print.php", result_lv, "POST");
}


code ใน php

<?php
$name = $_POST['name'];
$site = $_POST['website'];

$your_data = "i am ".$name.". my blog is ".$site;

//เปิด file เพื่อเขียน
$fp = fopen("textfile.txt", "w");

//เขียน ลง file ที่เปิดไว้
fwrite($fp, $your_data);

//ปิด file
fclose($fp);
?>



เมื่อเปิด textfile.txt มาก็จะมีข้อความว่า

"i am flashas. my blog is http://flashas.exteen.com"

 

Flash action script : Work with Component

ListBox Family Component

Entry นี้จะมาลองใช้ Component ถึง 3 อย่าง พร้อม ๆ กัน คือ
1.ComboBox - เลือกได้ item เดียว
2.List - เลือกหลาย item ก็ได้
3.Grid - เลือกหลาย item ก็ได้ แต่ว่า มันโชว์ในรูปแบบ ตารางได้

งั้นมาลองใช้กันเลย
1. ลาก component 3 อย่างที่จะใช้ไปใส่ไว้ที่ Library รวมทั้ง TextArea ด้วย (ไว้แสดงค่า)
2. ใส่ code ที่ frame แรกดังนี้


//สร้าง instance ของ TextArea และ กำหนด properties ต่างๆ
this.createClassObject(mx.controls.TextArea,"myTextArea",0);
myTextArea.move(20,20);
myTextArea.text = "Please select item in any components";
myTextArea.setSize(400,50);
myTextArea.wordWrap = true;
myTextArea.html = true;

//สร้าง instance ของ ComboBox และกำหนด properties ต่าง
this.createClassObject(mx.controls.ComboBox,"myComboBox",1);
myComboBox.move(20,80);
myComboBox.addItem("Mike","56");
myComboBox.addItem("Naomi","45");
myComboBox.addItem("Pugkung","80");

//สร้าง listener เพื่อรองรับ event ที่เกิดขึ้น กับ ComboBox
var cb_Listener:Object = new Object();
cb_Listener.change = function(evtObj:Object){
myTextArea.text = evtObj.target.selectedItem.label + " is "
+ evtObj.target.selectedItem.data + " kilograms";
}
myComboBox.addEventListener("change",cb_Listener);

//สร้าง instance ของ List และกำหนด properties ต่าง
this.createClassObject(mx.controls.List,"myList",2);
myList.move(20,120);
//add items to list and add thier datas
myList.addItem({label:"Mike",data1:"140",data2:"10"});
myList.addItem({label:"Naomi",data1:"160",data2:"18"});
myList.addItem({label:"Pugkung",data1:"178",data2:"24"});

//สร้าง listener เพื่อรองรับ event ที่เกิดขึ้น กับ List
var li_Listener:Object = new Object();
li_Listener.change = function(evtObj:Object){
var selectedObj:Object = evtObj.target.selectedItem;
myTextArea.text = selectedObj.label + " is "+ selectedObj.data2
+ "<br>and height is "+selectedObj.data1;
}
myList.addEventListener("change",li_Listener);

//สร้าง instance ของ DataGrid และกำหนด properties ต่าง
this.createClassObject(mx.controls.DataGrid,"myDataGrid",4);
myDataGrid.move(20,240);
myDataGrid.setSize(200,150);
//set column name เพื่อไว้ให้รู้ว่าแต่ละ column คืออะไร
myDataGrid.columnNames = ["Name","Sex","Country"];
//add item to datagrid
myDataGrid.addItem({Name:"Mike",Sex:"Male",Country:"USA",called:"man"});
myDataGrid.addItem({Name:"Naomi",Sex:"Female",Country:"Japan",called:"woman"});
myDataGrid.addItem({Name:"Pugkung",Sex:"Male",Country:"Korea",called:"man"});
//สร้าง listener เพื่อรองรับ event ที่เกิดขึ้น กับ DataGrid
var dg_Listener:Object = new Object();
dg_Listener.change = function(evtObj:Object){
var selectedObj:Object = evtObj.target.selectedItem;
myTextArea.text = selectedObj.Name + " is a " + selectedObj.called + " who lives in "
+ selectedObj.Country;
}
myDataGrid.addEventListener("change",dg_Listener);


จะเห็นว่า ในการใช้ datagrid นั้น ตอนที่ addItem ไป เราใส่ ค่าไป 4 ค่า แต่ ค่าที่แสดงผลบน datagrid นั้นมีแค่ 3 คือ ซึ่ง 3 ค่านี้มัน map กับ columnNames ที่ set ไว้ และ ส่วนอีกค่า(called) เราก็สามารถ กำหนดไว้ตอน addItem แล้วมาเรียกใช้ได้เช่นกัน

posted by flashas, at 2006-May-29 13:08:422

RadioButton Component

Radio button นั้น ต่างกับ checkbox ตรงที่ ใน 1 group มันจะเลือกได้แค่อันเดียว เพราะฉะนั้น flash เอง จึงมี property ที่มันเป็น group ให้อยู่แล้ว ไม่ต้องมานั่งทำเหมือน checkbox ใน entry ที่แล้ว

1.ลาก component TextArea, RadioButton และ Button ไปใส่ไว้ที่ Library
2.ใส่ code ที่ frame แรก ดังนี้


//สร้าง instance ของ TextArea
this.createClassObject(mx.controls.TextArea,"myTextArea",0);
//กำหนด properties ต่าง ๆ
myTextArea.move(20,10);
myTextArea.setSize(200,30);
myTextArea.text = "Select choice";

//loop สร้าง instance ของ RadioButton
for(var i:Number=1;i<4;i++){
this.createClassObject(mx.controls.RadioButton,"myRadioButton"+i,i);
_root["myRadioButton"+i].move(20,(20*i)+40);
_root["myRadioButton"+i].label = "RadioButton"+i;
//set groupName ของ RadioButton พวกนี้
_root["myRadioButton"+i].groupName = "choiceGroup";
}

//สร้าง instance ของ button
this.createClassObject(mx.controls.Button,"myButton",10);
myButton.move(20,150);
myButton.label = "ok";

//สร้าง listener เพื่อมารับ event ของ button
var myListener:Object = new Object();
myListener.click = function(){
var selectedRadioButton = choiceGroup.selection;
myTextArea.text = "you select "+selectedRadioButton.label;
}
myButton.addEventListener("click",myListener);

posted by flashas, at 2006-May-29 01:21:150

CheckBox Component [2]

จาก Entry ที่แล้ว เราได้สร้าง checkBox component จากการวนลูป ซึ่งชื่อของ instance มันก็จะอยู่ในรูปแบบ "xxxN"

Q : แล้วทีนี้ ถ้าจะใช้ checkBox เยอะ แต่ให้มันมีชื่อในแบบฉบับของตัวเองแล้วเวลา check จะ check ยังไง ?
A : ทำเป็น group แล้วใช้ condition check group ดังนี้

1.ลาก component Label,CheckBox,Button ไปไว้ใน Library
2.ใส่ code ดังนี้ที่ Frame แรก


//create label and set its properties.
this.createClassObject(mx.controls.Label,"myLabel",10);
myLabel.move(20,0);
myLabel.autoSize = "left";
myLabel.text = "nothing is checked";

//create checkboxs and set thier properties.
this.createClassObject(mx.controls.CheckBox,"firstBox",1);
firstBox.move(20,20);
firstBox.label = "1 st checkbox";

this.createClassObject(mx.controls.CheckBox,"secondBox",2);
secondBox.move(20,40);
secondBox.label = "2 nd checkbox";

this.createClassObject(mx.controls.CheckBox,"thirdBox",3);
thirdBox.move(20,60);
thirdBox.label = "3 rd checkbox";

//create button and set its properties
this.createClassObject(mx.controls.Button,"myButton",4);
myButton.move(20,80);
myButton.label = "OK";

//set group name ของแต่ละ checkbox
var GROUP_NAME = "groupname";
firstBox.group = GROUP_NAME;
secondBox.group = GROUP_NAME;
thirdBox.group = GROUP_NAME;


var myForm = this;

//create Listener for listen events
var myListener:Object = new Object();

//listener listen event "click"
myListener.click = function(){
var showText:String = "";
var hasCheck:Boolean = false;
//loop throught in myForm
for(var i in myForm){
var current_Item = myForm[i];

//check group ของ item ปัจจุบัน ที่ถูกเลือก ว่า มี grop เป็น "groupname" หรือไม่
if(current_Item.group == GROUP_NAME && current_Item.selected){
showText += current_Item.label+" ";
hasCheck = true;
}
}
if(hasCheck){
myLabel.text = showText+" is checked";
}else{
myLabel.text = "nothing is checked";
}
}

//addEventListener to myButton
myButton.addEventListener("click",myListener);

 

25 กรกฎาคม 2552

จัดการภาษาไทย (UTF-8) ด้วย Multibyte String Functions

จัดการภาษาไทย (UTF-8) ด้วย Multibyte String Functions

UTF-8 ใช้พื้นที่ 3 ไบต์ ในการเก็บข้อมูลภาษาไทย 1 อักขระ ดังนั้นจึงไม่สามารถใช้ฟังก์ชัน เช่น strlen() และ substr() กับภาษาไทยที่เป็น UTF-8 ได้ เช่น

$string = "ที่นี่abcd1234";

echo 'strlen() return: '.strlen($string);

ผลลัพธ์ที่ได้คือ

strlen() return: 26

ตัวเลข 26 มาจาก ภาษาไทย 6×3 = 18, ภาษาอังกฤษ 4 และตัวเลข 4 ตัว

ดังนั้นเพื่อให้นับจำนวนตัวอักขระได้อย่างถูกต้องจะต้องใช้ฟังก์ชัน multibyte string เช่น จากตัวอย่างข้างต้น จะต้องใช้ฟังก์ชัน mb_strlen() แทน strlen()

$string = "ที่นี่abcd1234";

echo 'mb_strlen() return: '.mb_strlen($string, 'utf-8');

ผลลัพธ์ที่ได้คือ:

strlen() return: 14

จะเห็นว่าได้ผลลัพธ์ตามที่ควรจะเป็นคือ ภาษาไทย 6, ภาษาอังกฤษ 4 และ ตัวเลข 4 ตัว

ในทำนองเดียวกัน เมื่อต้องการตัดประโยคให้สั้นลง เช่น ต้องการเลือกมาเพียง 3 ตัวอักษรแรก เราจะไม่สามารถใช้ substr() กับภาษาไทยที่ encode ด้วย UTF-8 ได้

$new_string = substr($string, 0, 3);

echo $new_string;

ผลลัพท์ที่ได้คือ:

เพื่อให้ได้ผลลัพธ์ถูกต้องตามที่ต้องการ เราจึงต้องใช้ mb_substr() แทน substr()

$new_string = mb_substr($string, 0, 3,'utf-8');

echo $new_string;

ผลลัพท์ที่ได้คือ:

ที่

จากตัวอย่างข้างต้น จะเห็นว่าจะต้องระบุพารามิเตอร์ตัวที่ 4 คือ encoding เป็น UTF-8 เข้าไปด้วย เพื่อป้องกันไม่ให้เกิดความผิดพลาดในการใช้งาน เราจึงควรใช้ฟังก์ชัน mb_internal_enconde() กำหนดให้การ encode เป็น UTF-8 ในบรรทัดแรกๆ ของโปรแกรมเลย เช่น

echo mb_internal_encoding();

mb_internal_encoding('utf-8');

echo "<br />";

echo mb_internal_encoding();

ผลลัพธ์ทีได้คือ

ISO-8859-1

UTF-8

นอกจากนี้ เราสามารถใช้ฟังก์ชัน iconv_substr() ในการตัดคำด้วยเช่นกัน

$new_string = iconv_substr($string, 0, 3,'utf-8');

echo $new_string;

ผลลัพท์ที่ได้คือ:

ที่