search

php中文字符串长度及定长截取问题使用str_len("中国") 结果为6,php系统默认一个中文字符长度为3,可改用mb_strlen函数获得长度,mb_substr函数截取字符

mb_strlen($str, "utf-8"); //1汉字为1字符
mb_strlen($str, "gb2312"); //系统会认为1汉字为2字符
mb_strlen($str); //如果没有添加,系统会认为1汉字为3字符

int mb_strlen ( string str [, string encoding] )

string mb_substr ( string str, int start [, int length [, string encoding]] ) 判断php变量是否定义,是否为空

if($keyword): 这样的语句如果在controller里没有set 到页面上判断语句会出错,改用表达式 isset($keyword)

表达式 gettype() empty() is_null() isset() boolean : if($x)
$x = ""; string TRUE FALSE TRUE FALSE
$x = null; NULL TRUE TRUE FALSE FALSE
var $x; NULL TRUE TRUE FALSE FALSE
$x is undefined NULL TRUE TRUE FALSE FALSE
$x = array(); array TRUE FALSE TRUE FALSE
$x = false; boolean TRUE FALSE TRUE FALSE
$x = true; boolean FALSE FALSE TRUE TRUE
$x = 1; integer FALSE FALSE TRUE TRUE
$x = 42; integer FALSE FALSE TRUE TRUE
$x = 0; integer TRUE FALSE TRUE FALSE 获取request多值参数

类似java的request.getParameterValues() (居然刚知道这个方法,==!)

页面form中 
后台处理请求

$kword=$_POST['kword'];

cakePHP对应方法为

$kword=$this->params['form']['kword'];

使用时按照设置的顺序$kword[index] index: 0-n php solr client api 取doc字段出现index not defined 错误解决方法:

solr文档可能某些字段不全,当取多个文档显示时,如果有的字段没有定义值会出现index not defined 错误

修改solr client api的Document文件
public function __get($key) {
//key不存在则返回空 避免出现index not defined 错误 shen guanpu 2010年7月15日13:51:52
return array_key_exists($key,$this->_fields)?$this->_fields[$key]:"";
//return $this->_fields[$key]; 原代码} Install CakePHP in a Subdirectory Via an Apache Alias
httpd.conf

In httpd.conf, add the following line:Alias /directory_name /absolute/path/to/install/directory/app/webroot
.htaccess

In app/webroot/.htaccess, add the following line:RewriteBase /directory_name
Your .htaccess file should now appear as such:


RewriteEngine On
RewriteBase /directory_name
RewriteCond % REQUEST_FILENAME !-d
RewriteCond % REQUEST_FILENAME !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

index.php

Finally, in app/webroot/index.php, at line 63, right below where it says not to edit below this line, change it to: define('WEBROOT_DIR', 'directory_name');
出处http://www.chriscassell.net/log/2006/07/27/how_to_install_.html mysql 远程访问设置

GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY 'password' WITH GRANT OPTION;

FLUSH PRIVILEGES; PHP 闭合标签

PHP闭合标签“?>”在PHP中对PHP的分析器是可选的。 但是,如果使用闭合标签,任何由开发者,用户,或者FTP应用程序插入闭合标签后面的空格都有可能会引起多余的输出、php错误、之后的输出无法显示、空白页。因此,所有的php文件应该省略这个php闭合标签,并插入一段注释来标明这是文件的底部并定位这个文件在这个应用的相对路径。这样有利于你确定这个文件已经结束而不是被删节的。

INCORRECT:

CORRECT:
/* End of file myfile.php // Location: ./system/modules/mymodule/myfile.php */ php判断数字

bool is_numeric ( mixed var ) mysql IGNORE_SPACE mode
写concat函数时出现 concat dose not exist错误

更改set sql_mode='IGNORE_SPACE'; 再写concat得到正确结果

mysql workbench字体太小,函数和“(”之间有空格居然没看到。。。 php solr 搜索排序

 $response = $this->searchSolr->search( $query, $offset, $limit,array('sort'=>'wiki-recommend desc,wiki-score desc') ); 字符编码转换

string mb_convert_encoding ( string str, string to_encoding [, mixed from_encoding] )  cakePHP之XP下apache配置

php.ini文件设置 date.timezone = HongKong 不然cakePHP首页会出现警告

apache httpd.conf配置主要是设置php支持及urlrewrite模块启动

LoadModule php5_module C:/php/php5apache2_2.dll

AddType application/x-httpd-php .php
PHPIniDir "C:/php"

#使用cake php 则去掉下行的注释
LoadModule rewrite_module modules/mod_rewrite.so


DirectoryIndex index.html index.php


# 配置默认的目录设置 是否允许跳转.
#

Options FollowSymLinks
AllowOverride all
# Order deny,allow
# Deny from all


# This should be changed to whatever you set DocumentRoot to.
#这个目录的配置同上做更改 二维数组赋值

$a1 = array( "a" => 0, "b" => 1 );
$a2 = array( "aa" => 00, "bb" => 11 );
$together = array( $a1, $a2 );
foreach( $together as $single ) {
$single["c" ] = 3 ;
}

这样赋值不会有任何变化,必须如下做法:

foreach( $together as $key => $value ) {
$together[$key]["c"] = 3 ;
} 使用yum 安装和删除PHP
# rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
# vi /etc/yum.repos.d/utterramblings.repo
[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
# yum search php
# yum update php mysql导出数据
导出表结构 mysqldump --opt -d shorturl -htestdb -utest -ptest> test.sql
导出数据和表结构 mysqldump 数据库名 -uroot -p > xxx.sql  
导出数据 mysqldump -t 数据库名 -uroot -p > xxx.sql  
导出特定表mysqldump -uroot -p -B数据库名 --table 表名 > xxx.sql  
如出现无权限锁表问题  mysqldump --opt --single-transaction -d love  -ulove -plove> love.sql mysql slave 恢复:  Fixing MySQL replication after slaves's relay log was corrupted 
http://www.redips.net/mysql/replication-slave-relay-log-corrupted/
首先 show slave status\G;  记录两个值:Relay_Master_Log_File  Exec_Master_Log_Pos

OK, with this values, new binlog position can be set:

# stop slave

mysql> stop slave;

# make slave forget its replication position in the master's binary log

mysql> reset slave;

# change slave to start reading from stopped position

mysql> change master to master_log_file='mysql-bin.002045', master_log_pos=103641119;

# start slave

mysql> start slave;

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do you set the session cookie parameters in PHP?How do you set the session cookie parameters in PHP?Apr 22, 2025 pm 05:33 PM

Setting session cookie parameters in PHP can be achieved through the session_set_cookie_params() function. 1) Use this function to set parameters, such as expiration time, path, domain name, security flag, etc.; 2) Call session_start() to make the parameters take effect; 3) Dynamically adjust parameters according to needs, such as user login status; 4) Pay attention to setting secure and httponly flags to improve security.

What is the main purpose of using sessions in PHP?What is the main purpose of using sessions in PHP?Apr 22, 2025 pm 05:25 PM

The main purpose of using sessions in PHP is to maintain the status of the user between different pages. 1) The session is started through the session_start() function, creating a unique session ID and storing it in the user cookie. 2) Session data is saved on the server, allowing data to be passed between different requests, such as login status and shopping cart content.

How can you share sessions across subdomains?How can you share sessions across subdomains?Apr 22, 2025 pm 05:21 PM

How to share a session between subdomains? Implemented by setting session cookies for common domain names. 1. Set the domain of the session cookie to .example.com on the server side. 2. Choose the appropriate session storage method, such as memory, database or distributed cache. 3. Pass the session ID through cookies, and the server retrieves and updates the session data based on the ID.

How does using HTTPS affect session security?How does using HTTPS affect session security?Apr 22, 2025 pm 05:13 PM

HTTPS significantly improves the security of sessions by encrypting data transmission, preventing man-in-the-middle attacks and providing authentication. 1) Encrypted data transmission: HTTPS uses SSL/TLS protocol to encrypt data to ensure that the data is not stolen or tampered during transmission. 2) Prevent man-in-the-middle attacks: Through the SSL/TLS handshake process, the client verifies the server certificate to ensure the connection legitimacy. 3) Provide authentication: HTTPS ensures that the connection is a legitimate server and protects data integrity and confidentiality.

The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.