作者LPH66 (ha(ruhi|yate)ism)
看板PHP
标题Re: [请益] 看不懂preg_replace函数的使用范例
时间Thu Jun 28 09:36:22 2007
※ 引述《fillmore (.......................)》之铭言:
: ※ 引述《fillmore (.......................)》之铭言:
: : 我用的是'/([^"]+)[\\]/'单引号括会错=> missing terminating] for character class
: : 但是'/([^"]+)[\\\\]/' 这样就没错
: : 不知道为什麽?
: 例子
: window.location=\'http://test.orz/download.php?session=25586136a8\'
: 这样写是正确=> '/http:\/\/test.orz\/download.php[?]session[=]([^"]+)[\\\\]/'
: 但是 [\\\\] 改成 [\\] 却是错误
我错了Orz
单引号只会处理\\和\'而已 其他不会处理
所以\还是得写四个
--
'Oh, Harry, dont't you
see?' Hermione breathed. 'If she could have done
one thing to make
absolutely sure that every single person in this school
will read your interview, it was
banning it!'
---'Harry Potter and the order of the phoenix', P513
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 192.192.197.115
1F:→ foxzgerald:我还是转不过来 = =" 可以解释一下吗? 06/28 20:26
2F:→ LPH66:单引号的escape sequence只处理\\和\' 06/29 05:41
3F:→ LPH66:所以当你需要一个字串内含两个反斜线时一定要打四个 06/29 05:41
4F:→ LPH66:这样处理出来才是一个含有两个反斜线的字串 06/29 05:42
5F:推 fillmore:总之单引号要辨别\\字串就要打\\\\四个 06/29 09:20
6F:推 buganini:一层给PHP parser看,另一层给PCRE parser看 07/02 20:18