最優(yōu)良人 » 字符串 http://www.dgkai.cn/blog 中山php|最優(yōu)網(wǎng)絡(luò) Mon, 13 May 2013 04:56:43 +0000 en hourly 1 http://wordpress.org/?v=3.1.4 php反斜線引用字符串 http://www.dgkai.cn/blog/view-114.html http://www.dgkai.cn/blog/view-114.html#comments Sun, 14 Aug 2011 17:09:38 +0000 lin http://www.dgkai.cn/blog/?p=114

addslashes:使用反斜線引用字符串 ,返回字符串,該字符串為了數(shù)據(jù)庫查詢語句等的需要在某些字符前加上了反斜線,這些字符是單引號(hào)(')、雙引號(hào)(")、反斜線(\)與 NUL(NULL 字符)。

stripslashes 相反的操作,或者如果系統(tǒng)自動(dòng)開啟了魔法引號(hào)(默認(rèn)是開啟的),如果想得到原來沒被轉(zhuǎn)義過的字符串,可以使用此函數(shù)

比如在正則的逆向引用中:
$find[] = "/<a(.*)href=(\"|')?(\/.*)(\"|'|\s)/Uei";
$replace[] ="stripslashes(str_replace('$','$@&#','$0'));";
去掉php自動(dòng)加上的反斜杠

]]>
http://www.dgkai.cn/blog/view-114.html/feed 19
判斷一個(gè)數(shù)組里是否都是空字符串 http://www.dgkai.cn/blog/view-74.html http://www.dgkai.cn/blog/view-74.html#comments Sat, 13 Aug 2011 17:10:57 +0000 lin http://www.dgkai.cn/blog/?p=74

有時(shí)我們要把一個(gè)全為空字符串組成的數(shù)組如:array('','','');當(dāng)成是空對(duì)待,因?yàn)槔锩娌缓魏螖?shù)據(jù)

使用empty()顯然是不行的,因?yàn)槔锩姘巳齻€(gè)值,只是這些值都是空字符串,用count()也不可以

那么可以用一種變通的方式,先把數(shù)組用implode轉(zhuǎn)換成字符串,再判斷字符串是否為真就可以了:

$a=array('','');

$a = implode('',$a);i

f($a)'為真';

else echo '為假';

]]>
http://www.dgkai.cn/blog/view-74.html/feed 3
php字符串首字母轉(zhuǎn)換大小寫 http://www.dgkai.cn/blog/view-48.html http://www.dgkai.cn/blog/view-48.html#comments Sat, 13 Aug 2011 10:04:36 +0000 lin http://www.dgkai.cn/blog/?p=48 首字母變大寫:ucwords()

<?php
$foo = 'hello world!';
$foo = ucwords($foo); // Hello World!

$bar = 'HELLO WORLD!';
$bar = ucwords($bar); // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>

第一個(gè)詞首字母變大寫:ucfirst()

<?php
$foo = 'hello world!';
$foo = ucfirst($foo); // Hello world!

$bar = 'HELLO WORLD!';
$bar = ucfirst($bar); // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?>

第一個(gè)詞首字母小寫lcfirst()

<?php
$foo = 'HelloWorld';
$foo = lcfirst($foo); // helloWorld

$bar = 'HELLO WORLD!';
$bar = lcfirst($bar); // hELLO WORLD!
$bar = lcfirst(strtoupper($bar)); // hELLO WORLD!
?>

字母變大寫:strtoupper()

字母變小寫:strtolower()

]]>
http://www.dgkai.cn/blog/view-48.html/feed 19