Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

ฟังก์ชัน convert_cyr_string() ใน PHP

คำอธิบาย

ฟังก์ชัน convert_cyr_string() ใช้แปลงสตริงจากชุดอักขระ Cyrillic ชุดหนึ่งไปอีกชุดหนึ่ง ใช้สำหรับภาษารัสเซียและภาษาสลาฟตะวันออก ฟังก์ชันนี้ถูก deprecated ใน PHP 7.4 และลบออกใน PHP 8.0 ให้ใช้ mb_convert_encoding() หรือ iconv() แทน

ชุดอักขระที่รองรับ

  • k - koi8-r
  • w - windows-1251
  • i - iso8859-5
  • a - x-cp866
  • d - x-cp866
  • m - x-mac-cyrillic

รูปแบบการใช้งาน (Syntax)

convert_cyr_string(string $string, string $from, string $to): string

พารามิเตอร์

  • string - สตริงที่ต้องการแปลง
  • from - ชุดอักขระต้นทาง (ตัวอักษรเดียว)
  • to - ชุดอักขระปลายทาง (ตัวอักษรเดียว)

ค่าที่คืนกลับ (Return Value)

คืนค่าสตริงที่แปลงแล้ว

ตัวอย่างการใช้งาน

<?php
$s = "Welcome to the website! æøå";
echo $s . "
"; echo convert_cyr_string($s, 'w', 'a'); ?>

ผลลัพธ์

Welcome to the website! æøå
Welcome to the website! ¦è¥

คำเตือน: ฟังก์ชันนี้ถูกลบออกใน PHP 8.0+ ให้ใช้ mb_convert_encoding() แทน