zoukankan      html  css  js  c++  java
  • php 常见问题

    empty(trim($str))报错原因

    一个if判断如下:

    if (!empty(trim($a))) { ... }
    

    报出如下错误:

    Fatal error: Can't use function return value in write context in ...
    

    如下形式则不报错误

    $ch_url = trim($a);
    if (!empty($a)) { ... }
    

    经过查询php手册,发现两个函数的使用方法为:

    bool empty( mixed var );
    string trim( string str [, string charlist] );
    

    错误就出现在这里了,原来empty()接收的是参数是一个变量,而trim()返回值为字符串,所以报错

    Note:
    在 PHP 5.5 之前,empty() 仅支持变量;任何其他东西将会导致一个解析错误。换言之,下列代码不会生效: empty(trim($name))。 作为替代,应该使用trim($name) == false.
    没有警告会产生,哪怕变量并不存在。 这意味着 empty() 本质上与 !isset($var) || $var == false 等价。

    Fatal error: Call to undefined function mb_strimwidth() in ...

    All mb_* functions are provided by a PHP extension called Multibyte String, internal name mbstring

    You probably don't have the extension active or installed. On most Linux distros you can install the package php-mbstring to install and activate this extension.

    Apache needs to be restarted afterwards if you are using mod_php
    我用的系统为centos 7.0, 用yum安装
    yum install php-mbstring

  • 相关阅读:
    231. Power of Two
    204. Count Primes
    205. Isomorphic Strings
    203. Remove Linked List Elements
    179. Largest Number
    922. Sort Array By Parity II
    350. Intersection of Two Arrays II
    242. Valid Anagram
    164. Maximum Gap
    147. Insertion Sort List
  • 原文地址:https://www.cnblogs.com/flowerszhong/p/6108101.html
Copyright © 2011-2022 走看看