-2

I'm a very beginner PHP programmer.

I want to create a search function for the first time, as well as an email verification by myself. I learned a little about regular expressions in Java, but I don't know how exactly to use them in PHP.

For example, how would I use the example "\\w{3,}@\\w{2,}\.\\ w{2,}? (and, are there errors in this code?) It is very simple and not very secure, as it is just a test site.

In Java, I can use Pattern.compile() and pattern.matcher() and matcher.find() to find matches. What is the PHP equivalent?

I've searched around a little bit - they all give examples on how to create good regular expressions, but I don't know what the syntax is for utilizing them.

Could somebody explain this to me, or redirect me to a useful site?

Thanks in advance.

Jonathan Lam
  • 16,831
  • 17
  • 68
  • 94
  • 2
    Email verification with regexes? Don't do it: http://stackoverflow.com/a/201378/344643 – Waleed Khan Oct 01 '13 at 19:54
  • So you know how to write them.. but you don't know how to write them..? – Sterling Archer Oct 01 '13 at 19:54
  • search what(text\db ..) ? that will depend on how you use them –  Oct 01 '13 at 19:54
  • 1
    See the [docs on `preg_match`](http://us2.php.net/manual/en/function.preg-match.php) and friends. – Waleed Khan Oct 01 '13 at 19:55
  • You can use preg_match, preg_match_all, preg_replace, etc... Btw for example if you want to search for items in the stock of your webshop, then you will search in database, not in php... – inf3rno Oct 01 '13 at 19:57
  • @Jon You can edit your question and provide PHP code where you have written a regex without using it. This would show that you have really tried something and is kind of polite on this site. And don't forget to accept an answer once you are satisfied. – Scolytus Oct 01 '13 at 20:05
  • @Scolytus thanks. I'll remember that from now on using this site. – Jonathan Lam Oct 01 '13 at 20:14
  • @Jon never mind :) Also think about addressing the other commenter's issues. For example: is there a DB involved? And as your question is on hold, read the link to the help center provided in the gray box and understand it ;) – Scolytus Oct 01 '13 at 20:25

2 Answers2

2

Here is the function that you are probably looking for. Returns a boolean.

http://php.net/manual/en/function.preg-match.php

andrewgrz
  • 435
  • 3
  • 6
0

http://www.php.net/manual/en/ref.pcre.php

The manual is always a good place to start.

Community
  • 1
  • 1
Mattt
  • 1,780
  • 14
  • 15