草庐IT

php - 在 PHP : (*UTF8) Works on Windows but not Linux 中使用 preg_match 匹配 UTF 字符

我有一个简单的正则表达式来检查用户名:preg_match('/(*UTF8)^[[:alnum:]]([[:alnum:]]|[_.-])+$/i',$username);在本地测试中(使用WAMP的Windows7),这将允许用户名使用UTF字符(例如é或ñ)。但是,当我在实际托管网站的服务器上进行测试时,我收到以下警告:Warning:preg_match()[function.preg-match]:Compilationfailed:(*VERB)notrecognizedatoffset5in/home/sites/vgmusic.com/test/Core/Impl/Fo

PHP:如何获取 preg_match_all 的字符串索引?

假设我有两个正则表达式,/eat(apple|pear)//Ilike/和文字"Iliketoeatapplesonarainyday,butonsunnydays,Iliketoeatpears."我想要的是用preg_match得到如下索引:match:0,5(Ilike)match:10,19(eatapples)match:57,62(Ilike)match:67,75(eatpears)有没有什么方法可以使用preg_match_all获取这些索引,而无需每次都循环遍历文本?编辑:解决方案PREG_OFFSET_CAPTURE! 最佳答案

php - preg_match 中的符号是什么意思?

我在离线借用的代码片段中有这个表达式。它强制新用户的密码不仅需要大写+小写+数字,而且必须按此顺序!如果我输入lower+upper+numbers,它会失败!if(preg_match("/^.*(?=.{4,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/",$pw_clean,$matches)){我在网上搜索过,但找不到可以告诉我某些字符含义的资源。我可以看到模式是preg_match("/someexpression/",yourstring,yourmatch).这些是什么意思:1.^-???2..*-???3.(?=.{4,})-requir

php - preg_match 验证 URL slug

我让用户在我的网站上创建他们自己的个人资料,这样他们就可以选择他们的url。因此,例如,如果他们的名字是JohnSmith,他们可能想输入john-smith,然后他们的个人资料URL将是www.mysite.com/john-smith。我需要使用preg_match来验证他们输入的是一个有效的URLslug。所以这里是它必须满足的规则才有效:它必须至少包含一个字母,并且只能包含字母、数字和连字符谁能帮帮我,我擅长PHP,但对正则表达式很垃圾! 最佳答案 我希望这段代码是不言自明的:但如果不是,函数test_username()将

php - preg_replace : converting line breaks into paragraphs

我想将换行符转换为段落。例如$string="1stparagraph2ndparagraph3rdparagraph";我想得到,1stparagraph2ndparagraph3rdparagraph和,$string="1stparagraph2ndparagraphalinebreak3rdparagraph";进入,1stparagraph2ndparagraphalinebreak3rdparagraphregex和reg_replace是否可行?或者其他更好的东西-xpath?我试过了,还没有结果,echopreg_replace("'/^(.*?)(\s*)+/'","

php - 如何在 preg_match() 中匹配重音字符?

我读过howaccentedcharactersmightsometimesmatch[a-z].我想知道的是如何匹配特定的重音字符。显然,preg_match('/[ñ]/','ñ')不起作用。 最佳答案 使用/u修饰符。这将为正则表达式启用Unicode。http://php.net/manual/en/reference.pcre.pattern.modifiers.php 关于php-如何在preg_match()中匹配重音字符?,我们在StackOverflow上找到一个类似的

php - 使用 php preg_replace 更改 html 链接的 href 属性

我正在尝试用不同的URL替换大字符串中的所有链接href。使用以下代码似乎只替换了第二个链接,而第一个链接完好无损,有人可以帮我吗?$string_of_text='PHPApache';echopreg_replace('//','',$string_of_text); 最佳答案 代替任何字符。使用任何非(^)引号[^"]echopreg_replace('//','',$string_of_text); 关于php-使用phppreg_replace更改html链接的href属性,我

php - 如何使用 preg_replace 在 PHP 中转义 $?

我正在使用preg_replace来转义特殊字符:$tmpStr=preg_replace("/\?/","\?",$tmpStr);$tmpStr=preg_replace("/\#/","\#",$tmpStr);$tmpStr=preg_replace("/\^/","\^",$tmpStr);$tmpStr=preg_replace("/\&/","\&",$tmpStr);$tmpStr=preg_replace("/\*/","\*",$tmpStr);$tmpStr=preg_replace("/\(/","\(",$tmpStr);$tmpStr=preg_replac

PHP preg_match 长度 3276 限制

在某些情况下,PHP的preg_match似乎对匹配重复字符有3276个字符的限制。即^(.|\s){0,3276}$有效,但^(.|\s){0,3277}$无效。它似乎并不总是适用,因为/^(.){0,3277}$/有效。我无法在PHP文档或错误跟踪器中的任何地方找到它。数字3276似乎有点奇怪,我唯一能想到的是它大约是32767的1/10,这是有符号16位整数的极限。preg_last_error()返回0。我已经在http://www.phpliveregex.com/上重现了这个问题以及我的本地系统和网络服务器。编辑:看起来我们从代码中得到“警告:preg_match():编译

php - preg_match :print: class matches tab character

for($i=0;$i";elseecho"chr($i)doesntmatch:print:";在我的Windows系统上,chr(9)的输出是:chr(9)matches:print:同样的代码,在Linux系统上,输出为:chr(9)doesntmatch:print:为什么:print:类仅在Windows上匹配\t?PHP5.5.12 最佳答案 这可能是语言环境问题,但您手头上一定有一个非常时髦的语言环境。POSIX规定没有cntrl可以print,没有space或blank可以print除非它是空格字符本身。在“C”语言