php7.0-dev : Depends: libpcre3-dev but it is not going to be installed 作者: lovingyu_er 时间: 2019-12-23 17:27:06 分类: 编程语言,PHP 评论 服务器上,在安装php-dev的时候,出现下面的错误: ```bash ubuntu@ota:~$ sudo apt-get install php7.0-dev Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: php7.0-dev : Depends: libpcre3-dev but it is not going to be installed E: Unable to correct problems, you have held broken packages. ``` 解决方案: ```bash ubuntu@ota:~$ sudo apt-get install libpcre3=2:8.38-3.1 libpcre3-dev=2:8.38-3.1 Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libpcre16-3 libpcre32-3 libpcrecpp0v5 The following NEW packages will be installed: libpcre16-3 libpcre3-dev libpcre32-3 libpcrecpp0v5 The following packages will be DOWNGRADED: libpcre3 0 upgraded, 4 newly installed, 1 downgraded, 0 to remove and 398 not upgraded. Need to get 1,043 kB of archives. After this operation, 3,594 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://mirrors.aliyun.com/ubuntu xenial/main amd64 libpcre3 amd64 2:8.38-3.1 [223 kB] Get:2 http://mirrors.aliyun.com/ubuntu xenial/main amd64 libpcrecpp0v5 amd64 2:8.38-3.1 [15.2 kB] Get:3 http://mirrors.aliyun.com/ubuntu xenial/main amd64 libpcre16-3 amd64 2:8.38-3.1 [144 kB] Get:4 http://mirrors.aliyun.com/ubuntu xenial/main amd64 libpcre32-3 amd64 2:8.38-3.1 [136 kB] Get:5 http://mirrors.aliyun.com/ubuntu xenial/main amd64 libpcre3-dev amd64 2:8.38-3.1 [525 kB] Fetched 1,043 kB in 0s (1,496 kB/s) dpkg: warning: downgrading libpcre3:amd64 from 2:8.41-4+ubuntu14.04.1+deb.sury.org+1 to 2:8.38-3.1 (Reading database ... 156456 files and directories currently installed.) Preparing to unpack .../libpcre3_2%3a8.38-3.1_amd64.deb ... Unpacking libpcre3:amd64 (2:8.38-3.1) over (2:8.41-4+ubuntu14.04.1+deb.sury.org+1) ... Processing triggers for libc-bin (2.23-0ubuntu3) ... Processing triggers for man-db (2.7.5-1) ... Setting up libpcre3:amd64 (2:8.38-3.1) ... Processing triggers for libc-bin (2.23-0ubuntu3) ... Selecting previously unselected package libpcrecpp0v5:amd64. (Reading database ... 156456 files and directories currently installed.) Preparing to unpack .../libpcrecpp0v5_2%3a8.38-3.1_amd64.deb ... Unpacking libpcrecpp0v5:amd64 (2:8.38-3.1) ... Selecting previously unselected package libpcre16-3:amd64. Preparing to unpack .../libpcre16-3_2%3a8.38-3.1_amd64.deb ... Unpacking libpcre16-3:amd64 (2:8.38-3.1) ... Selecting previously unselected package libpcre32-3:amd64. Preparing to unpack .../libpcre32-3_2%3a8.38-3.1_amd64.deb ... Unpacking libpcre32-3:amd64 (2:8.38-3.1) ... Selecting previously unselected package libpcre3-dev:amd64. Preparing to unpack .../libpcre3-dev_2%3a8.38-3.1_amd64.deb ... Unpacking libpcre3-dev:amd64 (2:8.38-3.1) ... Processing triggers for libc-bin (2.23-0ubuntu3) ... Processing triggers for man-db (2.7.5-1) ... Setting up libpcrecpp0v5:amd64 (2:8.38-3.1) ... Setting up libpcre16-3:amd64 (2:8.38-3.1) ... Setting up libpcre32-3:amd64 (2:8.38-3.1) ... Setting up libpcre3-dev:amd64 (2:8.38-3.1) ... Processing triggers for libc-bin (2.23-0ubuntu3) ... ``` 下面就可以安装```php-dev```了。
mac book pro (ubuntu)安装yar扩展:error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/ 作者: lovingyu_er 时间: 2019-12-19 14:45:00 分类: 编程语言,PHP 评论 在使用macbook pro安装php扩展yar的时候,出现下面的错误提示: 编译命令: ```bash sudo ./configure --with-php-config=/usr/local/bin/php-config --enable-msgpack ``` 错误提示: ```bash Macbook pro error: Please reinstall the libcurl distribution - easy.h should be in /include/curl/ ``` 我在网上搜索了很多次,以为是本身的curl的问题,经过几次```reinstall curl``` 发现不行,查看了```config.m4``` 发现这里的```curl-dir```应该是php的curl扩展,果断打开php-fpm的```phpinfo()```函数,找到了```--with-curl=/usr/local/opt/curl-openssl```,在编译的时候,执行如下的命令: ```bash sudo ./configure --with-php-config=/usr/local/bin/php-config --enable-msgpack --with-curl=/usr/local/opt/curl-openssl ``` 在进行编译,发现没有问题喽,问题就解决了。原来使用的```pecl install yar``` 发现这样是不行的,只能通过编译安装呀,这一点要注意。可能会```msgpack```包,用户可以在```https://github.com/msgpack/msgpack-php.git``` 仓库去下载安装 ###ubuntu系统上 我在ubuntu系统上出现了上述同样的情况,是缺少安装包导致的,只需要安装一下即可, ```sudo apt-get install libcurl4-gnutls-dev``` 再进行```configure```的时候,就不会出现上述的问题,就可以安心的安装扩展```yar```了
php判断是否是命令行模式 作者: lovingyu_er 时间: 2019-12-15 19:14:00 分类: PHP 评论 在进行判断php是否是命令行模式的时候,在网上看到一些有意思的例子,比如其中一个博主是使用正则表达式处理的: ``` function is_cli(){ return preg_match("/cli/i", php_sapi_name()) ? true : false; } ``` 这个是正则表达式处理的,官方的用法如下: ```bash $sapi_type = php_sapi_name(); if (substr($sapi_type, 0, 3) == 'cgi') { echo "You are using CGI PHP\n"; } else { echo "You are not using CGI PHP\n"; } ``` 个人觉得,如果想要判断是否命令行,因为命令行暂时用不到的web服务器,```php_sapi_name()```函数,返回的结果大概如下: ``` aolserver、apache、 apache2filter、apache2handler、 caudium、cgi (直到 PHP 5.3), cgi-fcgi、cli、 cli-server、 continuity、embed、fpm-fcgi、 isapi、litespeed、 milter、nsapi、 phttpd、pi3web、roxen、 thttpd、tux 和 webjames。 ``` 可以使用如下的代码: ```bash function is_cli() { return (PHP_SAPI === 'cli' OR defined('STDIN')); } ``` 其中```PHP_SAPI```常量和```php_sapi_name()```函数的作用相似。 上面的函数还会监测是否定义了```STDIN```常量
mac系统 git 不出现自动补全的功能 作者: lovingyu_er 时间: 2019-12-11 09:31:00 分类: 编程语言,mac 系统 评论 google了一把,解决方案如下: 需要使用到git-completion 软件,使用```brew``` 安装,如果你的mac还没有安装,请自行到```Homebrew```官网下载安装。 如果没有安装```git```以后,在安装好```Homebrew```以后,需要安装```git-completion``` 插件,你先可以查看一下该安装包的一些信息 ``` brew info git-completion``` 执行安装: ``` brew install git-completion``` 安装完成以后,使用```git ``` 相关命令发现不行,我google了一下,可以将下面的一些代码加入到```.bash_profile``` ```bash source ~/.git-completion.bash [ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion ``` 如果上述中的```.git-completion.bash```文件不存在,请在你的当前用户的家目录中添加如下的内容,也就是```.git-completion.bash``` 脚本中要执行的脚本内容,内容可以参考```git-completion```的网址:```https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash``` 放到 ```~/.git-completion.bash```文件里面,最后执行一下 ```source .bash_profile``` 即可。 再使用```git ``` 的相关的命令行的时候,就可以使用```tab``` 按键自动补全的功能。
php实现插入排序算法 作者: lovingyu_er 时间: 2019-12-10 12:35:00 分类: 数据结构和算法之美,PHP 评论 参考文档:维基百科```插入排序``` 插入排序介绍: 1.从第一个元素开始,该元素可以认为已经被排序(sorted arr,这也是为啥) 2.取出下一个元素,在已经排序的元素序列中从后向前扫描 3.如果该元素(已排序)大于新元素,将该元素移到下一位置 4.重复步骤3,直到找到已排序的元素小于或者等于新元素的位置 5.将新元素插入到该位置后 6. 重复步骤2~5 php的算法实现如下: ```bash arr = $arr; } public function insertSort(){ echo "origin:".PHP_EOL; foreach($this->arr as $key=>$item){ echo "key :".$key." => ".$item.PHP_EOL; } $length = count($this->arr); $i = 0; //$i=0的元素是已经排序好的元素 for($i=1;$i<$length;$i++){ $tmp = $this->arr[$i]; //拿排序好的列表与$i=1比较,找到比较合适的位置,将$i放到已经排序好的列表中的合适的位置 for($j = $i-1;$j>=0&&$j<$length;$j--){ if($this->arr[$j]>$tmp){ $this->arr[$j+1] = $this->arr[$j]; $this->arr[$j]=$tmp; } } } echo "sorted arr".PHP_EOL; foreach ($this->arr as $k=>$item){ echo "key :".$key." => ".$item.PHP_EOL; } } } $arr = [83, 2, 44, 21, 2, 23, 3, 322, 1111,1.5,1.0,1.001]; $insertSort = new InsertSort($arr); $insertSort->insertSort(); //算法参考的文档: ///https://zh.wikipedia.org/zh-hans/%E6%8F%92%E5%85%A5%E6%8E%92%E5%BA%8F /// ```