\b BS
$str=""
$str =str_replace("\b", "", $str);
//echo
$str =str_replace(chr(8), "", $str);
//echo
$str =str_replace("\\b", "", $str);
//echo
·´Ð±ÏßÓжàÖÖÓ÷¨¡£Ê×ÏÈ£¬Èç¹û½ô½Ó×ÅÊÇÒ»¸ö·Ç×ÖĸÊý×Ö×Ö·û£¬±íÃ÷È¡Ïû ¸Ã×Ö·ûËù´ú±íµÄÌØÊâºÒå¡£ÕâÖÖ½«·´Ð±Ïß×÷ΪתÒå×Ö·ûµÄÓ÷¨ÔÚ×Ö·ûÀà ÄÚ²¿ºÍÍⲿ¶¼¿ÉÓá£
±ÈÈ磬Èç¹ûÄãÏ£ÍûÆ¥ÅäÒ»¸ö "*" ×Ö·û£¬¾ÍÐèÒªÔÚģʽÖÐдΪ "\*"¡£ ÕâÊÊÓÃÓÚÒ»¸ö×Ö·ûÔÚ²»½øÐÐתÒå»áÓÐÌØÊ⺬ÒåµÄÇé¿öÏ¡£ µ«ÊÇ£¬ ¶ÔÓÚ·ÇÊý×Ö×ÖĸµÄ×Ö·û£¬×ÜÊÇÔÚÐèÒªÆä½øÐÐÔÎÄÆ¥ÅäµÄʱºòÔÚËüÇ°ÃæÔö¼ÓÒ»¸ö·´Ð±Ïߣ¬ À´ÉùÃ÷Ëü´ú±í×Ô¼º£¬ÕâÊÇ°²È«µÄ¡£Èç¹ûҪƥÅäÒ»¸ö·´Ð±Ïߣ¬ÄÇôÔÚģʽÖÐʹÓà "\\"¡£
Note:
·´Ð±ÏßÔÚµ¥ÒýºÅ×Ö·û´®ºÍË«ÒýºÅ×Ö·û´® Öж¼ÓÐÌØÊ⺬Ò壬Òò´ËҪƥÅäÒ»¸ö·´Ð±Ïߣ¬ ģʽÖбØÐëдΪ "\\\\"¡£ Òë×¢£º "/\\/"£¬ Ê×ÏÈËü×÷Ϊ×Ö·û´®£¬·´Ð±Ïß»á½øÐÐתÒ壬 ÄÇôתÒåºóµÄ½á¹ûÊÇ/\/£¬Õâ¸ö²ÅÊÇÕýÔò±í´ïʽÒýÇæÄõ½µÄģʽ£¬ ¶øÕýÔò±í´ïʽÒýÇæÒ²ÈÏΪ \ ÊÇתÒå±ê¼Ç£¬Ëü»á½«·Ö¸ô·û / ½øÐÐתÒ壬 ´Ó¶øµÃµ½µÄÊÇÒ»¸ö´íÎó£¬Òò´Ë£¬ÐèÒª 4 ¸ö·´Ð±Ï߲ſÉÒÔÆ¥ÅäÒ»¸ö·´Ð±Ïß¡£
Èç¹ûÒ»¸öģʽ±»Ê¹Óà PCRE_EXTENDED Ñ¡Ïî±àÒ룬 ģʽÖеĿհ××Ö·û(³ýÁË×Ö·ûÀàÖеÄ)ºÍδתÒåµÄ#µ½ÐÐÄ©µÄËùÓÐ×Ö·û¶¼»á±»ºöÂÔ¡£ ÒªÔÚÕâÖÖÇé¿öÏÂʹÓÿհ××Ö·û»òÕß#£¬¾ÍÐèÒª¶ÔÆä½øÐÐתÒå¡£
·´Ð±ÏߵĵڶþÖÖÓÃ;ÌṩÁËÒ»ÖÖ¶Ô·Ç´òÓ¡×Ö·û½øÐпɼû±àÂëµÄ¿ØÖÆÊֶΡ£ ³ýÁ˶þ½øÖÆµÄ 0 »áÖÕ½áÒ»¸öģʽÍ⣬²¢²»»áÑϸñµÄÏÞÖÆ·Ç´òÓ¡×Ö·û(×ÔÉí)µÄ³öÏÖ£¬ µ«Êǵ±Ò»¸öģʽÒÔÎı¾±à¼Æ÷µÄ·½Ê½±à¼×¼±¸µÄʱºò£¬ ʹÓÃÏÂÃæµÄתÒåÐòÁÐÏà±ÈʹÓöþ½øÖÆ×Ö·û»á¸ü¼ÓÈÝÒס£
\cxµÄÈ·ÇÐЧ¹ûÈçÏ£º Èç¹ûxÊÇÒ»¸öСд×Öĸ£¬Ëü±»×ª»»Îª´óд¡£½Ó×Å£¬ ½«×Ö·ûµÄµÚ6λ(Ê®Áù½øÖÆ 40£¬ÓÒÊýµÚÒ»¸öλΪµÚ0λ)È¡·´¡£ ±ÈÈç\cz³ÉΪʮÁù½øÖƵÄ1A£¬\c{³ÉΪʮÁù½øÖÆ3B£¬ \c;³ÉΪʮÁù½øÖÆ7B¡£
ÔÚ"\x"ºóÃ棬¶ÁÈ¡Á½¸öÊ®Áù½øÖÆÊý(×Öĸ¿ÉÒÔÊÇ´óд»òСд)¡£ ÔÚUTF-8ģʽ£¬ "\x{...}"ÔÊÐíʹÓ㬠»¨À¨ºÅÄÚµÄÄÚÈÝÊÇÊ®Áù½øÖÆÓÐЧÊý×Ö¡£ Ëü½«¸ø³öµÄÊ®Áù½øÖÆÊý×Ö½âÊÍΪ UTF-8 ×Ö·û´úÂë¡£ÔÀ´µÄÊ®Áù½øÖÆתÒåÐòÁУ¬ \xhh£¬ Æ¥ÅäÒ»¸öË«×Ö½ÚµÄUTF-8×Ö·û£¬Èç¹ûËüµÄÖµ´óÓÚ127
ÔÚ"\0"Ö®ºó£¬ ¶ÁÈ¡Á½¸ö°Ë½øÖÆÊý¡£ËùÓÐÇé¿öÏ£¬Èç¹ûÊýÉÙÓÚ2¸ö£¬ÔòÖ±½ÓʹÓᣠÐòÁÐ "\0\x\07" Ö¸¶¨ÁËÁ½¸ö¶þ½øÖÆ 0 ½ô¸ú×ÅÒ»¸ö BEL ×Ö·û¡£ ÇëÈ·±£³õʼµÄ 0 Ö®ºóµÄÁ½¸öÊý×ÖÊǺϷ¨µÄ°Ë½øÖÆÊý¡£
´¦ÀíÒ»¸ö·´Ð±Ïß½ô¸ú×ŵIJ»ÊÇ0µÄÊý×ÖµÄÇé¿ö±È½Ï¸´ÔÓ¡£ÔÚ×Ö·ûÀàÍⲿ£¬ PCRE ¶ÁÈ¡Ëü²¢ÒÔÊ®½øÖƶÁÈ¡½ôËæÆäºóµÄÊý×Ö¡£ Èç¹ûÊýֵСÓÚ 10£¬ »òÕß֮ǰ²¶»ñµ½Á˸ÃÊý×ÖÄܹ»´ú±íµÄ×óÀ¨ºÅ(×Ó×é)£¬ Õû¸öÊý×ÖÐòÁб»ÈÏΪÊǺóÏòÒýÓ᣺óÏòÒýÓÃÈçºÎ¹¤×÷ÔÚºóÃæÃèÊö£¬ ½ÓÏÂÀ´¾Í»áÌÖÂÛÀ¨ºÅ×Ó×é¡£
ÔÚÒ»¸ö×Ö·ûÀàÀïÃ棬»òÕßÊ®½øÖÆÊý´óÓÚ 9 ²¢ÇÒûÓÐÄÇô¶àµÄ×Ó×é±»²¶»ñ£¬ PCRE ÖØжÁÈ¡·´Ð±ÏߺóµÄµÚÈý¸ö 8 ½øÖÆÊý×Ö£¬²¢ÇÒ´Ó×îµÍµÄ 8 λÉú³Éµ¥×Ö½ÚÖµ¡£ ÈκεĺóÐøÊý×Ö¶¼´ú±íËüÃÇ×ÔÉí¡£ÀýÈ磺
×¢Ò⣬°Ë½øÖÆÖµµÄ 100 »òÕ߸ü´óµÄÖµ±ØÐëûÓÐÇ°ÖõÄ0Òýµ¼£¬ ÒòΪÿ´Î×î¶à¶ÁÈ¡3¸ö8½øÖÆλ.
ËùÓÐÐòÁж¨ÒåµÄµ¥×Ö½ÚÖµ¶¼¿ÉÒÔÔÚ×Ö·ûÀàÄÚ²¿»òÍⲿʹÓá£ÁíÍ⣬ÔÚ×Ö·ûÀàÖÐ, ÐòÁÐ "\b" ½âÊÍΪÍ˸ñ×Ö·û¡£×Ö·ûÀàÍâËüÓÖÓв»Í¬µÄÒâÒå(ÏÂÃæÓÐÃèÊö)
·´Ð±ÏߵĵÚÈýÖÖÓ÷¨ÊÇÓÃÀ´ÃèÊöÌض¨µÄ×Ö·ûÀࣺ
ÉÏÃæÿһ¶ÔתÒåÐòÁж¼´ú±íÁËÍêÕû×Ö·û¼¯ÖÐÁ½¸ö²»ÏཻµÄ²¿·Ö£¬ ÈÎÒâ×Ö·ûÒ»¶¨»áÆ¥ÅäÆäÖÐÒ»¸ö£¬Í¬Ê±Ò»¶¨²»»áÆ¥ÅäÁíÍâÒ»¸ö¡£
µ¥´Ê×Ö·ûÖ¸µÄÊÇÈÎÒâ×Öĸ¡¢Êý×Ö¡¢Ï»®Ïß¡£ Ò²¾ÍÊÇ˵ÈÎÒâ¿ÉÒÔ×é³Éperlµ¥´ÊµÄ×Ö·û¡£ ×ÖĸºÍÊý×ֵĶ¨Òåͨ¹ýPCRE×Ö·û±í¿ØÖÆ£¬¿ÉÒÔͨ¹ýÖ¸¶¨µØÓòÉèÖÃʹÆäÆ¥Åä¸Ä±ä¡£±ÈÈ磬 ÔÚ·¨¹ú (fr) µØÓòÉèÖÃÖУ¬Ò»Ð©³¬¹ý 128 µÄ×Ö·û´úÂë±»ÓÃÓÚÖØÒô×Öĸ£¬ ËüÃÇ¿ÉÒÔʵÓà \w Æ¥Åä¡£
ÕâЩ×Ö·ûÀàÐòÁÐÔÚ×Ö·ûÀàÄÚ²¿»òÍⲿ¶¼¿ÉÒÔ³öÏÖ¡£ ËûÃÇÿ´ÎÆ¥ÅäËù´ú±íµÄ×Ö·ûÀàÐÍÖеÄÒ»¸ö×Ö·û¡£ Èç¹ûµ±Ç°Æ¥ÅäµãλÓÚÄ¿±ê×Ö·û´®Ä©Î²£¬ ËüÃÇÖеÄËùÓÐ×Ö·û¶¼Æ¥Åäʧ°Ü£¬ ÒòΪûÓÐ×Ö·ûÈÃËüÃÇÆ¥ÅäÁË¡£
·´Ð±ÏߵĵÚËÄÖÖÓ÷¨ÊÇһЩ¼òµ¥µÄ¶ÏÑÔ¡£ Ò»¸ö¶ÏÑÔÖ¸¶¨Ò»¸ö±ØÐëÔÚÌض¨Î»ÖÃÆ¥ÅäµÄÌõ¼þ£¬ ËüÃDz»»á´ÓÄ¿±ê×Ö·û´®ÖÐÏûºÄÈκÎ×Ö·û¡£ ½ÓÏÂÀ´ÎÒÃÇ»áÌÖÂÛʹÓÃ×Ó×éµÄ¸ü¼Ó¸´ÔӵĶÏÑÔ¡£ ·´Ð±Ï߶ÏÑÔ°üÀ¨£º
ÕâЩ¶ÏÑÔ²»ÄܳöÏÖÔÚ×Ö·ûÀàÖÐ(µ«ÊÇ×¢Ò⣬ "\b"ÔÚ×Ö·ûÀàÖÐÓв»Í¬µÄÒâÒ壬 ±íʾµÄÊÇÍ˸ñ(backspace)×Ö·û)
Ò»¸öµ¥´Ê±ß½ç±íʾµÄÊÇÔÚÄ¿±ê×Ö·û´®ÖУ¬ µ±Ç°×Ö·ûºÍÇ°Ò»¸ö×Ö·û²»Í¬Ê±Æ¥Åä\w»ò\W(Ò»¸ö±ÈÅä\w, Ò»¸öÆ¥Åä\W)£¬ »òÕß×÷Ϊ×Ö·û´®¿ªÊ¼»ò½áβ×Ö·ûµÄʱºòµ±Ç°×Ö·ûÆ¥Åä\w¡£
\A£¬ \Z£¬ \z¶ÏÑÔ²»Í¬ÓÚ´«Í³µÄ^ºÍ$(Ïê¼ûÏÂÎÄ)£¬ ÒòΪËûÃÇÓÀԶƥÅäÄ¿±ê×Ö·û´®µÄ¿ªÊ¼ºÍ½á⣬¶ø²»»áÊÜģʽÐÞÊηûµÄÏÞÖÆ¡£ ËüÃDz»ÊÜPCRE_MULTILINE£¬PCRE_DOLLAR_ENDONLYÑ¡ÏîµÄÓ°Ïì¡£ \Z ºÍ \z Ö®¼äµÄ²»Í¬ÔÚÓÚµ±×Ö·û´®½áÊø×Ö·ûʱ»»Ðзûʱ \Z »á½«Æä¿´×ö×Ö·û´®½áβƥÅä, ¶ø \z ֻƥÅä×Ö·û´®½áβ¡£
\G ¶ÏÑÔÔÚÖ¸¶¨ÁË$offset
²ÎÊýµÄpreg_match() µ÷ÓÃÖУ¬
½öÔÚµ±Ç°Æ¥ÅäλÖÃÔÚÆ¥Å俪ʼµãµÄʱºò²ÅÊdzɹ¦µÄ¡£
µ± $offset
µÄÖµ²»Îª 0 µÄʱºò£¬
ËüÓë \A ÊDz»Í¬µÄ¡£ Òë×¢£ºÁíÍâÒ»µãÓë \A µÄ²»Í¬Ö®´¦ÔÚÓÚʹÓà preg_match_all() ʱ£¬
ÿ´ÎÆ¥Åä \G Ö»ÊǶÏÑÔÊÇ·ñÊÇÆ¥Åä½á¹ûµÄ¿ªÊ¼Î»Öã¬
¶ø \A ¶ÏÑÔµÄÔòÊÇÆ¥Åä½á¹ûµÄ¿ªÊ¼Î»ÖÃÊÇ·ñÔÚÄ¿±ê×Ö·û´®¿ªÊ¼Î»Öá£
×Ô PHP 4.3.3¿ªÊ¼£¬ \Q ºÍ \E ¿ÉÒÔÓÃÓÚÔÚģʽÖкöÂÔÕýÔò±í´ïʽԪ×Ö·û¡£±ÈÈ磺 \w+\Q.$.\E$ »áÆ¥ÅäÒ»¸ö»ò¶à¸öµ¥´Ê×Ö·û£¬½ô½Ó×ÅÒ»¸öµãºÅ£¬Ò»¸ö$£¬Ò»¸öµãºÅ£¬ ×îºóêÏò×Ö·û´®Ä©Î²¡£
×Ô PHP 5.2.4 ¿ªÊ¼¡£ \K ¿ÉÒÔÓÃÓÚÖØÖÃÆ¥Åä¡£ ±ÈÈ磬 foot\Kbar Æ¥Åä"footbar"¡£ µ«Êǵõ½µÄÆ¥Åä½á¹ûÊÇ "bar"¡£µ«ÊÇ£¬ \K µÄʹÓò»»á¸ÉÔ¤µ½×Ó×éÄÚµÄÄÚÈÝ£¬ ±ÈÈç (foot)\Kbar Æ¥Åä "footbar"£¬µÚÒ»¸ö×Ó×éÄڵĽá¹ûÈÔÈ»»áÊÇ "foo"¡£Òë×¢£º \K ·ÅÔÚ×Ó×éºÍ×Ó×éÍâÃæµÄЧ¹ûÊÇÒ»ÑùµÄ¡£
\b BS
$str=""
$str =str_replace("\b", "", $str);
//echo
$str =str_replace(chr(8), "", $str);
//echo
$str =str_replace("\\b", "", $str);
//echo
Some escape sequence like the tab character \t won't work inside single quotes '\t', But they work inside double quotes.
Other escape sequences like the backspace character won't work unless you use its ascii codepoint and chr() function i.e. chr(8)
You can use Unicode character escape sequences (tested on PHP 5.3.3 & PCRE 7.8).
<?php
//This source is supposed to be written in UTF-8.
$a='€';
var_dump(preg_match('/\\x{20ac}/u',$a)); //Match!
Using \R in character classes is NOT possible:
var_dump( preg_match('#\R+#',"\n") ); -> int(1)
var_dump( preg_match('#[\R]+#',"\n") ); -> int(0)
The pattern "/\\A/" may be replaced by "/\\\A/" in order to match a "\A" string. Any other escaped "\" looks to work fine so you can use "/\\S/", for instance, to match a "\S" string.
"line break" is ill-defined:
-- Windows uses CR+LF (\r\n)
-- Linux LF (\n)
-- OSX CR (\r)
Little-known special character:
\R in preg_* matches all three.
preg_match( '/^\R$/', "match\nany\\n\rline\r\nending\r" ); // match any line endings
As \v matches both single char line ends (CR, LF) and double char (CR+LF, LF+CR), it is not a fixed length atom (eg. is not allowed in lookbehind assertions).