Overview

Namespaces

  • Kotchasan
    • Cache
    • Database
    • Http
    • Log
    • Orm
  • None
  • PDF
  • PHP
  • Psr
    • Cache
    • Http
      • Message
    • Log

Classes

  • Accordion
  • ArrayTool
  • CKEditor
  • Collection
  • Config
  • Controller
  • Country
  • Csv
  • Curl
  • Currency
  • Database
  • DataTable
  • Date
  • DOMNode
  • DOMParser
  • Email
  • File
  • Files
  • Form
  • Grid
  • Html
  • Htmldoc
  • HtmlTable
  • Image
  • InputItem
  • Inputs
  • KBase
  • Language
  • ListItem
  • Login
  • Menu
  • Mime
  • Model
  • Number
  • Object
  • Password
  • Pdf
  • Province
  • Router
  • Singleton
  • Tab
  • TableRow
  • Template
  • Text
  • Validator
  • View
  • Overview
  • Namespace
  • Class
  • Tree

Class Text

String functions.

Namespace: Kotchasan
Author: Goragod Wiriya admin@goragod.com
Since: 1.0
Located at Kotchasan/Text.php
Methods summary
public static string
# cut( string $source, integer $len )

ฟังก์ชั่น ตัดสตริงค์ตามความยาวที่กำหนด หากข้อความที่นำมาตัดยาวกว่าที่กำหนด จะตัดข้อความที่เกินออก และเติม .. ข้างท้าย.

ฟังก์ชั่น ตัดสตริงค์ตามความยาวที่กำหนด หากข้อความที่นำมาตัดยาวกว่าที่กำหนด จะตัดข้อความที่เกินออก และเติม .. ข้างท้าย.

Parameters

$source
ข้อความ
$len
ความยาวของข้อความที่ต้องการ (จำนวนตัวอักษรรวมจุด)

Returns

string

Assert

('สวัสดี ประเทศไทย', 8) [==] 'สวัสดี..'
('123456789', 8) [==] '123456..'
public static string
# formatFileSize( integer $bytes, integer $precision = 2 )

ฟังก์ชั่น แปลงขนาดของไฟล์จาก byte เป็น kb mb คืนค่าขนาดของไฟล์เป็น KB MB.

ฟังก์ชั่น แปลงขนาดของไฟล์จาก byte เป็น kb mb คืนค่าขนาดของไฟล์เป็น KB MB.

Parameters

$bytes
ขนาดของไฟล์ เป็น byte
$precision
จำนวนหลักหลังจุดทศนิยม (default 2)

Returns

string

Assert

(256) [==] '256 Bytes'
(1024) [==] '1 KB'
(1024 * 1024) [==] '1 MB'
(1024 * 1024 * 1024) [==] '1 GB'
(1024 * 1024 * 1024 * 1024) [==] '1 TB'
public static string
# highlighter( string $detail )

ฟังก์ชั่น HTML highlighter แปลง BBCode แปลงข้อความ http เป็นลิงค์ คืนค่าข้อความ

ฟังก์ชั่น HTML highlighter แปลง BBCode แปลงข้อความ http เป็นลิงค์ คืนค่าข้อความ

Parameters

$detail
ข้อความ

Returns

string
public static string
# htmlspecialchars( string $text, boolean $double_encode = true )

แปลง & " ' < > \ { } เป็น HTML entities ใช้แทน htmlspecialchars() ของ PHP.

แปลง & " ' < > \ { } เป็น HTML entities ใช้แทน htmlspecialchars() ของ PHP.

Parameters

$text
$double_encode
true (default) แปลง รหัส HTML เช่น & เป็น &amp;, false ไม่แปลง

Returns

string
public static string
# oneLine( string $text, integer $len = 0 )

ฟังก์ชั่น ลบช่องว่าง และ ตัวอักษรขึ้นบรรทัดใหม่ ที่ติดกันเกินกว่า 1 ตัว คืนค่าข้อความที่ไม่มีตัวอักษรขึ้นบรรทัดใหม่.

ฟังก์ชั่น ลบช่องว่าง และ ตัวอักษรขึ้นบรรทัดใหม่ ที่ติดกันเกินกว่า 1 ตัว คืนค่าข้อความที่ไม่มีตัวอักษรขึ้นบรรทัดใหม่.

Parameters

$text
ข้อความ
$len
จำนวนตัวอักษรสูงสุดที่ต้องการ, (default) คืนค่าทั้งหมด

Returns

string

Assert

(" \tทดสอบ\r\nภาษาไทย") [==] 'ทดสอบ ภาษาไทย'
public static string
# password( string $text )

รับค่าสำหรับ password อักขระทุกตัวไม่มีช่องว่าง.

รับค่าสำหรับ password อักขระทุกตัวไม่มีช่องว่าง.

Parameters

$text

Returns

string

Assert

(" 0\n12 34\r\r6\t5ทดสอบ@#$&{}!?+-=") [==] '0123465ทดสอบ@#$&{}!?+-='
public static string
# removeNonCharacters( string $text )

ลบตัวอักษรที่ไม่สามารถพิมพ์ได้ออก ตั้งแต่ chr(128)-chr(255) หรือ \x80-\xFF ขึ้นไปจะถูกลบออก

ลบตัวอักษรที่ไม่สามารถพิมพ์ได้ออก ตั้งแต่ chr(128)-chr(255) หรือ \x80-\xFF ขึ้นไปจะถูกลบออก

Parameters

$text

Returns

string

Assert

(chr(0).chr(127).chr(128).chr(255)) [==] chr(0).chr(127)
public static string
# repeat( string $text, integer $count )

ฟังก์ชั่นคืนค่าข้อความซ้ำๆตามจำนวนที่กำหนด.

ฟังก์ชั่นคืนค่าข้อความซ้ำๆตามจำนวนที่กำหนด.

Parameters

$text
ข้อความหรือตัวอักษรที่ต้องการทำซ้ำ
$count
จำนวนที่ต้องการ

Returns

string

Assert

('0', 10) [==] '0000000000'
public static string
# replace( string $source, array $replace )

แทนที่ข้อความด้วยข้อมูลจากแอเรย์ รองรับข้อมูลรูปแบบแอเรย์ย่อยๆ.

แทนที่ข้อความด้วยข้อมูลจากแอเรย์ รองรับข้อมูลรูปแบบแอเรย์ย่อยๆ.

Parameters

$source
ข้อความต้นฉบับ
$replace
ข้อความที่จะนำมาแทนที่ รูปแบบ array($key1 => $value1, $key2 => $value2) ข้อความใน $source ที่ตรงกับ $key จะถูกแทนที่ด้วย $value

Returns

string

Assert

("SELECT * FROM table WHERE id=:id AND lang IN (:lang, '')", array(':id' => 1, array(':lang' => 'th'))) [==] "SELECT * FROM table WHERE id=1 AND lang IN (th, '')"
public static string
# toEditor( string $text )

ฟังก์ชั่น เข้ารหัส อักขระพิเศษ และ {} ก่อนจะส่งให้กับ textarea หรือ editor ตอนแก้ไข & " ' < > { } ไม่แปลง รหัส HTML เช่น & &.

ฟังก์ชั่น เข้ารหัส อักขระพิเศษ และ {} ก่อนจะส่งให้กับ textarea หรือ editor ตอนแก้ไข & " ' < > { } ไม่แปลง รหัส HTML เช่น & &.

Parameters

$text
ข้อความ

Returns

string

Assert

('&"'."'<>{}&&") [==] "&"'<>{}&&"
public static string
# topic( string $text, boolean $double_encode = true )

แปลง tag และ ลบช่องว่างไม่เกิน 1 ช่อง ไม่ขึ้นบรรทัดใหม่ เช่นหัวข้อของบทความ

แปลง tag และ ลบช่องว่างไม่เกิน 1 ช่อง ไม่ขึ้นบรรทัดใหม่ เช่นหัวข้อของบทความ

Parameters

$text
$double_encode
true (default) แปลง รหัส HTML เช่น & เป็น &amp;, false ไม่แปลง

Returns

string

Assert

(' ทด\/สอบ'."\r\n\t".' ') [==] 'ทด\/สอบ <?php echo '555'?>'
(' ') [==] '&nbsp;'
(' ', false) [==] ' '
public static string
# unhtmlspecialchars( string $text )

แปลง htmlspecialchars กลับเป็นอักขระปกติ.

แปลง htmlspecialchars กลับเป็นอักขระปกติ.

Parameters

$text

Returns

string
public static string
# url( $text )

แปลง tag ไม่แปลง & และลบช่องว่างหัวท้าย สำหรับ URL หรือ email.

แปลง tag ไม่แปลง & และลบช่องว่างหัวท้าย สำหรับ URL หรือ email.

Returns

string

Assert

(" http://www.kotchasan.com?a=1&b=2&c=3 ") [==] 'http://www.kotchasan.com?a=1&b=2&c=3'
("javascript:alert('xxx')") [==] 'alertxxx'
("http://www.xxx.com/javascript/") [==] 'http://www.xxx.com/javascript/'
public static string
# username( string $text )

ฟังก์ชั่นรับค่าสำหรับใช้เป็น username รองรับอีเมล ตัวเลข (หมายเลขโทรศัพท์) @ - _ . เท่านั้น.

ฟังก์ชั่นรับค่าสำหรับใช้เป็น username รองรับอีเมล ตัวเลข (หมายเลขโทรศัพท์) @ - _ . เท่านั้น.

Parameters

$text

Returns

string

Assert

(' ad_min@demo.com') [==] 'ad_min@demo.com'
('012 3465') [==] '0123465'
kotchasan API documentation generated by ApiGen