發表文章

目前顯示的是有「PHP」標籤的文章

Markdown

[PHP] Check is Number

檢查金額是否為數字 https://stackoverflow.com/questions/8307104/is-numeric-vs-is-float-vs-is-int if is_numeric($input) === true then either is_float($input) === true OR is_int($input) === true OR 分別需要注意 第一種 0x36這種也過 第二種 整數或小數點 第三種 整數 [eric_tu@localhost ~]$ php -a Interactive shell php > echo intval(23); 23 php > echo intval(231asad); PHP Parse error: syntax error, unexpected 'asad' (T_STRING) in php shell code on line 1 php > echo intval('231asad'); 231 php > echo is_int('23'); php > echo intval(0x3123); 12579 php > echo intval('.x2130'); 0 php > is_numeric('123ads') php > echo is_numeric('123ads'); PHP Parse error: syntax error, unexpected echo (T_ECHO) in php shell code on line 2 php > echo preg_match('/^[0-9]*$/', '21313','asd21') php > echo preg_match('/^[0-9]*$/', '21313','asd21'); PHP Fatal error: Only variables can be passed by reference in php ...

[PHP] Parse/Syntax Errors; and How to solve them?

https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them Everyone runs into syntax errors. Even experienced programmers make typos. For newcomers it's just part of the learning process. However, it's often easy to interpret error messages such as: PHP Parse error: syntax error, unexpected '{' in index.php on line 20 The unexpected symbol isn't always the real culprit. But the line number gives a rough idea where to start looking. Always look at the  code context . The syntax mistake often hides in the mentioned  or  in  previous code lines . Compare your code against syntax examples from the manual. While not every case matches the other. Yet there are some  general steps to  solve syntax mistakes . This references summarized the common pitfalls: Unexpected T_STRING Unexpected T_VARIABLE Unexpected '$varname' (T_VARIABLE) Unexpected T_CONSTANT_ENCAPSED_STRING Unexpected T_ENCAPSED_AND_WHITESPACE U...

[PHP] yield

http://php.net/manual/en/language.generators.syntax.php Generator syntax  ¶ A generator function looks just like a normal function, except that instead of returning a value, a generator  yield s as many values as it needs to. When a generator function is called, it returns an object that can be iterated over. When you iterate over that object (for instance, via a foreach  loop), PHP will call the generator function each time it needs a value, then saves the state of the generator when the generator yields a value so that it can be resumed when the next value is required. Once there are no more values to be yielded, then the generator function can simply exit, and the calling code continues just as if an array has run out of values. Note : In PHP 5, a generator could not return a value: doing so would result in a compile error. An empty  return  statement was valid syntax within a generator and it would terminate the generator. Since PHP 7.0, a gener...

[php] dump

http://symfony.com/doc/current/components/var_dumper.html The VarDumper Component The VarDumper component provides mechanisms for extracting the state out of any PHP variables. Built on top, it provides a better  dump()  function that you can use instead of  var_dump . 今天才發現有這個function可以用,debug方便多了~ 例如把 $request dump() 出來 Request { #2 ▼ + attributes : ParameterBag { #6 ▼ # parameters : array:3 [ ▼ " _controller " => " AppBundle\Controller\DefaultController::createActioniAPI " " _route " => " apiAdd " " _route_params " => [] ] } + request : ParameterBag { #4 ▼ # parameters : [] } + query : ParameterBag { #5 ▼ # parameters : [] } + server : ServerBag { #9 ▼ # parameters : array:33 [ ▼ " USER " => " apache " " HOME " => " /usr/share/httpd " " FCGI_ROLE " => " RESPO...