preg_match() No ending deliminator found

ぃ、小莉子 提交于 2020-01-14 05:22:13

问题


I have read this and this, and this, and half a dozen other questions about preg_match on SO, and I still can't figure this one out.

I went to use this code from a CodeReview question and got an error saying that there was a preg_match() no deliminator '/' found.

Can someone help me fix it? The code in question is this statement:

if (preg_match($regex, $user_agent)) {

You can find it by going to the bottom of the new, edited version of the code in the question itself, and counting up approx 12 lines (not counting blank lines).


回答1:


Looking at the code posted on Code Review, in the $os_array there is the following line:

'/win16'                =>  'Windows 3.11',

It is missing the /i from the end of the regex on that line, which is probably causing your error. The line above that is also missing the i but this won't break anything.

As paxdiablo suggested, printing our your $regex variable inside the loop should have found this problem quickly.




回答2:


This is Debugging 101 stuff. Insert a statement immediately after:

foreach ($browser_array as $regex => $value) {

to print out the current values of $regex and $value.

That should (hopefully) show you exactly what it's complaining about.

This should also be done to the earlier array scan, where you would have found the errant '/win16', as picked up by JohnC.



来源:https://stackoverflow.com/questions/11336658/preg-match-no-ending-deliminator-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!