sree4u Posted July 4, 2013 Share Posted July 4, 2013 Dear All, I have a log file by the name of 192.168.229.128.log which has a particular pattern available like /opt/lampp/htdocs/enroll/192.168.229.128/. I want to check this pattern from this file and do some activities. the pattern matching i am giving is :- preg_match("/opt\/lampp\/htdocs\/enroll\/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\\\/", "$theData", $matches) Attached herewith is the log file and the source code. Please help to resolve this issue. Regards, Sreejith a.php 1.txt Quote Link to comment https://forums.phpfreaks.com/topic/279853-need-help-regarding-pattern-matching/ Share on other sites More sharing options...
DavidAM Posted July 5, 2013 Share Posted July 5, 2013 1) You have not stated a problem. What are you trying to accomplish; what is happening that should NOT happen; what is NOT happening that SHOULD happen. 2) Turn on error_reporting (in Development) so PHP will give you some help finding problems 3) I (personally) do NOT download attachments, and I'm sure a lot of others don't either. Post the pertinent code -- using ... tags preg_match("/opt\/lampp\/htdocs\/enroll\/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\\\/", "$theData", $matches) 4) Since you need slashes in the regular expression, choose a different delimiter so you don't have to keep escaping them: preg_match("~opt/lampp/htdocs/enroll/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\\/", "$theData", $matches) I always use the tilde, since it is rarely in anything I would be searching. 5) In making that change, it appears that there is no closing delimiter on your expression; and why are you putting a backslash at the end of it? Or did you just keep adding "\" until it "looked right"? It looks like you want the literal slash ("/") as part of the expression at the beginning and the end. The preg_ family of functions require a delimiter around the regular expression. So the first and last characters have to be the same and are NOT part of the expression. (Then, there can be modifiers after the closing delimiter) preg_match("~/opt/lampp/htdocs/enroll/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/~", "$theData", $matches) Quote Link to comment https://forums.phpfreaks.com/topic/279853-need-help-regarding-pattern-matching/#findComment-1439526 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.