[PHP]如何给一个变量赋长字符串
In the latest installment of the ongoing Developer.com PHP series,
I discuss the many improvements and additions to
<a href="http://www.php.net">PHP 5's</a> object-oriented architecture.
summary;
[PHP]如何去除字符串中的whitespace.
首先是whitespace的定义:任何在印刷术当中显示为空白的字符。包括以下:
Unicode记法
- U+0009–U+000D (control characters, containing Tab, CR and LF)
- U+0020 SPACE
- U+0085 NEL (control character next line)
- U+00A0 NBSP (NO-BREAK SPACE)
- U+1680 OGHAM SPACE MARK
- U+180E MONGOLIAN VOWEL SEPARATOR
- U+2000–U+200A (different sorts of spaces)
- U+2028 LS (LINE SEPARATOR)
- U+2029 PS (PARAGRAPH SEPARATOR)
- U+202F NNBSP (NARROW NO-BREAK SPACE)
- U+205F MMSP (MEDIUM MATHEMATICAL SPACE)
- U+3000 IDEOGRAPHIC SPACE
在php种,去除的方法主要有三种,这三种适用情况也不同。
1, trim — Strip whitespace (or other characters) from the beginning and end of a string
trim()这个函数只会去除字符串开头和结尾部分的部分whitespace,如下:
- " " (ASCII 32 (0x20)), an ordinary space.
- "\t" (ASCII 9 (0x09)), a tab.
- "\n" (ASCII 10 (0x0A)), a new line (line feed).
- "\r" (ASCII 13 (0x0D)), a carriage return.
- "\0" (ASCII 0 (0x00)), the NUL-byte.
- "\x0B" (ASCII 11 (0x0B)), a vertical tab.
但不会去除中间的whitespace,这一定要注意。
2, preg_replace — Perform a regular expression search and replace
用正则表达式来去除whitespace,这个就可以比较彻底了,去除一个字符串中所有的whitespace。具体代码如下:
$str = 'foo o';
$str = preg_replace('/\s/', '', $str);
// This will be 'fooo' now
echo $str;
?>
3, str_replace(' ',”
适合去除space,而非whitespace
[C]ANSI C中有哪些预处理指令?
1,文件包含
#include
2,宏替换
#define //定义某宏
#undef //取消某宏的定义
# //用来标识参数用作字符串
## //用来连接参数
3,条件包含
#if
#else
#elif
#endif
#ifdef
#ifndef
defined(name)是一个ANSI C中的一个表达式,用做#if的conditional expression,那为什么有了#ifdef,#ifndef还有用defined()呢?原因就在下面。
#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif
/* 有两个或两个以上的判断 */
#if !defined(PAGE_SIZE) && defined(BLOCK_SIZE)
#define PAGE_SIZE 4096
#endif