Overview

Namespaces

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

Classes

  • Accordion
  • ApiController
  • 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
  • ObjectTool
  • Password
  • Pdf
  • Province
  • Router
  • Session
  • Singleton
  • Tab
  • TableRow
  • Template
  • Text
  • Validator
  • View

Exceptions

  • ApiException
  • InputItemException
  • Overview
  • Namespace
  • Class
  • Tree

Class InputItem

Input Object

Namespace: Kotchasan
Author: Goragod Wiriya admin@goragod.com
Since: 1.0
Located at Kotchasan/InputItem.php
Methods summary
public
# __construct( mixed $value = null, string|null $type = null )

Class Constructer

Class Constructer

Parameters

$value
null (default)
$type
ประเภท Input เช่น GET POST SESSION COOKIE หรือ null ถ้าไม่ได้มาจากรายการข้างต้น
public mixed
# all( )

คืนค่าตามข้อมูลที่ส่งมา

คืนค่าตามข้อมูลที่ส่งมา

Returns

mixed
public string|array
# color( )

คืนค่า ค่าสี String หรือ แอเรย์ของ String

คืนค่า ค่าสี String หรือ แอเรย์ของ String

Returns

string|array

Assert

create('#000')->color() [==] '#000'
create('red')->color() [==] 'red'
public static static
# create( mixed $value, string|null $type = null )

สร้าง Object

สร้าง Object

Parameters

$value
$type
ประเภท Input เช่น GET POST SESSION COOKIE หรือ null ถ้าไม่ได้มาจากรายการข้างต้น

Returns

static
public string|array|null
# date( boolean $strict = false )

วันที่และเวลา คืนค่า null ถ้าข้อมูลวันที่ว่างเปล่าหรือมีรูปแบบไม่ถูกต้อง

วันที่และเวลา คืนค่า null ถ้าข้อมูลวันที่ว่างเปล่าหรือมีรูปแบบไม่ถูกต้อง

Parameters

$strict
true ตรวจสอบความถูกต้องของวันที่ด้วย, false (default) ไม่ต้องตรวจสอบ

Returns

string|array|null

Assert

create('2016-01-01 20:20:20')->date() [==] '2016-01-01 20:20:20'
create('2016-01-01 20:20:20')->date() [==] '2016-01-01 20:20:20'
create('2016-01-01 20:20:20')->date(true) [==] '2016-01-01 20:20:20'
create('20:20:20')->date() [==] '20:20:20'
create('20:20')->date() [==] '20:20'
create('20:20')->date(true) [==] '20:20:00'
create('2016-01-01')->date() [==] '2016-01-01'
create('')->date() [==] null
create(null)->date() [==] null
public string|array|null
# time( boolean $strict = false )

เวลา คืนค่า null ถ้าข้อมูลเวลาว่างเปล่า หรือเท่าบ --:--.

เวลา คืนค่า null ถ้าข้อมูลเวลาว่างเปล่า หรือเท่าบ --:--.

Parameters

$strict
true ตรวจสอบความถูกต้องของวันที่ด้วย, false (default) ไม่ต้องตรวจสอบ

Returns

string|array|null

Assert

create('20:20:20')->time() [==] '20:20:20'
create('--:--')->time() [==] null
create('')->time() [==] null
create('20:20:20')->time() [==] '20:20:20'
create('20:20')->time() [==] '20:20'
create('20:20')->time(true) [==] '20:20:00'
public string|array
# description( integer $len = 0 )

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

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

Parameters

$len
ความยาวของ description หมายถึงคืนค่าทั้งหมด

Returns

string|array

Assert

create("ท.ด(ส )อ\"บ'\r\n\t")->description() [==] 'ท.ด(ส )อ บ'
create('ทดสอบ')->description() [==] 'ทดสอบ'
create('ทดสอบตัวหนา')->description() [==] 'ทดสอบตัวหนา'
create('ทดสอบ{LNG_Language name}')->description() [==] 'ทดสอบ'
create('ทดสอบ[code]ตัวหนา[/code]')->description() [==] 'ทดสอบ'
create('ทดสอบ[b]ตัวหนา[/b]')->description() [==] 'ทดสอบตัวหนา'
create('2 > 1 < 3 > 2{WIDGET_XXX}')->description() [==] '2 > 1 < 3 > 2'
create('ทดสอบ')->description() [==] 'ทดสอบ'
create('ท&ด"\ /ส-อ+บ')->description() [==] 'ท ด \ /ส-อ+บ'
create('ภาคภูมิ')->description(2) [==] 'ภา'
create('U1.username ทดสอบภาษาไทย')->description(5) [throws] \Kotchasan\InputItemException
public string|array
# detail( )

ลบ PHP tag และแปลง \ { } สำหรับใช้รับข้อมูลจาก editor เช่นเนื้อหาของบทความ

ลบ PHP tag และแปลง \ { } สำหรับใช้รับข้อมูลจาก editor เช่นเนื้อหาของบทความ

Returns

string|array

Assert

create('{ทด\/สอบ}')->detail() [==] '{ทด\/สอบ}'
create('U1.username')->detail() [throws] \Kotchasan\InputItemException
public boolean
# exists( )

ตรวจสอบว่ามีตัวแปรส่งมาหรือไม่ คืนค่า true ถ้ามีตัวแปรส่งมา

ตรวจสอบว่ามีตัวแปรส่งมาหรือไม่ คืนค่า true ถ้ามีตัวแปรส่งมา

Returns

boolean
public string|array
# filter( string $format, string $replace = '' )

ฟังก์ชั่นแทนที่อักขระที่ไม่ต้องการ

ฟังก์ชั่นแทนที่อักขระที่ไม่ต้องการ

Parameters

$format
Regular Expression อักขระที่ยอมรับ เช่น \d\s-:
$replace
ข้อความแทนที่

Returns

string|array

Assert

create('admin,1234')->filter('0-9a-zA-Z,') [==] 'admin,1234'
create('adminกข,12ฟ34')->filter('0-9a-zA-Z,') [==] 'admin,1234'
create('U1.username')->filter('a-zA-Z0-9.') [throws] \Kotchasan\InputItemException
public boolean
# isCookie( )

ตรวจสอบว่ามาจาก $_COOKIE หรือไม่ คืนค่า true ถ้ามาจาก $_COOKIE.

ตรวจสอบว่ามาจาก $_COOKIE หรือไม่ คืนค่า true ถ้ามาจาก $_COOKIE.

Returns

boolean
public boolean
# isGet( )

ตรวจสอบว่ามาจาก $_GET หรือไม่ คืนค่า true ถ้ามาจาก $_GET

ตรวจสอบว่ามาจาก $_GET หรือไม่ คืนค่า true ถ้ามาจาก $_GET

Returns

boolean
public boolean
# isPost( )

ตรวจสอบว่ามาจาก $_POST หรือไม่ คืนค่า true ถ้ามาจาก $_POST

ตรวจสอบว่ามาจาก $_POST หรือไม่ คืนค่า true ถ้ามาจาก $_POST

Returns

boolean
public boolean
# isSession( )

ตรวจสอบว่ามาจาก $_SESSION หรือไม่ คืนค่า true ถ้ามาจาก $_SESSION

ตรวจสอบว่ามาจาก $_SESSION หรือไม่ คืนค่า true ถ้ามาจาก $_SESSION

Returns

boolean
public string|array
# keywords( integer $len = 0 )

ลบ tags และ ลบช่องว่างไม่เกิน 1 ช่อง ไม่ขึ้นบรรทัดใหม่ และลบช่องว่างหัวท้าย ใช้เป็น tags หรือ keywords

ลบ tags และ ลบช่องว่างไม่เกิน 1 ช่อง ไม่ขึ้นบรรทัดใหม่ และลบช่องว่างหัวท้าย ใช้เป็น tags หรือ keywords

Parameters

$len
ความยาวของ keywords หมายถึงคืนค่าทั้งหมด

Returns

string|array

Assert

create("ทด \r\nสอบ")->keywords() [==] 'ทด สอบ'
create('U1.username ทดสอบ')->keywords(5) [throws] \Kotchasan\InputItemException
public string|array
# number( )

ตัวเลข หรือ แอเรย์ของ ตัวเลข

ตัวเลข หรือ แอเรย์ของ ตัวเลข

Returns

string|array

Assert

create(12345)->number() [==] '12345'
create(0.12345)->number() [==] '012345'
create('ทด0123สอ4บ5')->number() [==] '012345'
public string|array
# password( )

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

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

Returns

string|array
public string|array
# quote( )

ฟังก์ชั่นรับข้อความ ยอมรับอักขระทั้งหมด และแปลง ' เป็น ' และลบช่องว่างหัวท้าย

ฟังก์ชั่นรับข้อความ ยอมรับอักขระทั้งหมด และแปลง ' เป็น ' และลบช่องว่างหัวท้าย

Returns

string|array

Assert

create("ทด'สอบ")->quote() [==] "ทด'สอบ"
create(' U1.username ')->quote() [throws] \Kotchasan\InputItemException
public string|array
# text( )

ฟังก์ชั่น แปลง & " ' < > \ เป็น HTML entities และลบช่องว่างหัวท้าย ใช้แปลงค่าที่รับจาก input ที่ไม่ยอมรับ tag

ฟังก์ชั่น แปลง & " ' < > \ เป็น HTML entities และลบช่องว่างหัวท้าย ใช้แปลงค่าที่รับจาก input ที่ไม่ยอมรับ tag

Returns

string|array

Assert

create(" ทด\/สอบ ")->text() [==] 'ทด\/สอบ<?php echo '555'?>'
create('U1.username')->text() [throws] \Kotchasan\InputItemException
public string|array
# textarea( )

แปลง < > \ { } เป็น HTML entities และแปลง \n เป็น
และลบช่องว่างหัวท้าย ใช้รับข้อมูลที่มาจาก textarea

แปลง < > \ { } เป็น HTML entities และแปลง \n เป็น
และลบช่องว่างหัวท้าย ใช้รับข้อมูลที่มาจาก textarea

Returns

string|array

Assert

create("ทด\/สอบ\n")->textarea() [==] "ทด\/สอบ\n<?php echo '$555'?>"
create('U1.username')->textarea() [throws] \Kotchasan\InputItemException
public boolean|array
# toBoolean( )

คืนค่าเป็น boolean หรือ แอเรย์ของ boolean

คืนค่าเป็น boolean หรือ แอเรย์ของ boolean

Returns

boolean|array

Assert

create(true)->toBoolean() [==] 1
create(false)->toBoolean() [==] 0
create(1)->toBoolean() [==] 1
create(0)->toBoolean() [==] 0
create(null)->toBoolean() [==] 0
public float|array
# toDouble( )

คืนค่าเป็น double

คืนค่าเป็น double

Returns

float|array

Assert

create(0.454)->toDouble() [==] 0.454
create(0.545)->toDouble() [==] 0.545
create('15,362.454')->toDouble() [==] 15362.454
public float|array
# toFloat( )

คืนค่าเป็น float หรือ แอเรย์ของ float

คืนค่าเป็น float หรือ แอเรย์ของ float

Returns

float|array

Assert

create(0.454)->toFloat() [==] 0.454
create(0.545)->toFloat() [==] 0.545
public integer|array
# toInt( )

คืนค่าเป็น integer หรือ แอเรย์ของ integer

คืนค่าเป็น integer หรือ แอเรย์ของ integer

Returns

integer|array

Assert

create(0.454)->toInt() [==] 0
create(2.945)->toInt() [==] 2
public object|array
# toObject( )

คืนค่าเป็น Object หรือ แอเรย์ของ Object

คืนค่าเป็น Object หรือ แอเรย์ของ Object

Returns

object|array

Assert

create('test')->toObject() [==] (object)'test'
public string|array|null
# toString( )

คืนค่าเป็น string หรือ แอเรย์ของ string หรือ null ฟังก์ชั่นนี้ใช้สำหรับรับค่าเป็น string โดยไม่ผ่านการตรวจสอบใดๆทั้งสิ้น ควรใช้อย่างระมัดระวัง

คืนค่าเป็น string หรือ แอเรย์ของ string หรือ null ฟังก์ชั่นนี้ใช้สำหรับรับค่าเป็น string โดยไม่ผ่านการตรวจสอบใดๆทั้งสิ้น ควรใช้อย่างระมัดระวัง

Returns

string|array|null

Assert

create('ทดสอบ')->toString() [==] 'ทดสอบ'
create('1')->toString() [==] '1'
create(1)->toString() [==] '1'
create(null)->toString() [==] null
public array
# toArray( )

คืนค่าเป็น array เท่านั้น ถ้าไม่ใช่แอเรย์จะ error

คืนค่าเป็น array เท่านั้น ถ้าไม่ใช่แอเรย์จะ error

Returns

array

Assert

create(array('one', 'two'))->toArray() [==] array('one', 'two')
public string|array
# topic( boolean $double_encode = true )

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

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

Parameters

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

Returns

string|array

Assert

create(' ทด\/สอบ'."\r\n\t".' ')->topic() [==] 'ทด\/สอบ <?php echo '555'?>'
create('U1.username')->topic() [throws] \Kotchasan\InputItemException
public string|array
# url( )

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

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

Returns

string|array

Assert

create(" http://www.kotchasan.com?a=1&b=2&c=3 ")->url() [==] 'http://www.kotchasan.com?a=1&b=2&c=3'
create("javascript:alert('xxx')")->url() [==] 'alertxxx'
create("http://www.xxx.com/javascript/")->url() [==] 'http://www.xxx.com/javascript/'
create('U1.username')->url() [throws] \Kotchasan\InputItemException
public string|array
# username( )

รับค่าอีเมลและหมายเลขโทรศัพท์เท่านั้น

รับค่าอีเมลและหมายเลขโทรศัพท์เท่านั้น

Returns

string|array

Assert

create(' admin@demo.com')->username() [==] 'admin@demo.com'
create('012 3465')->username() [==] '0123465'
create('U1.username')->username() [throws] \Kotchasan\InputItemException
Properties summary
protected string|null $type

ตัวแปรบอกประเภท Input เช่น GET POST SESSION COOKIE

ตัวแปรบอกประเภท Input เช่น GET POST SESSION COOKIE

#
protected mixed $value

ตัวแปรเก็บค่าของ Object

ตัวแปรเก็บค่าของ Object

#
Kotchasan API documentation generated by ApiGen