Diving into PHP: Day 7

I’m going to show you how to use regular expressions with PHP. Over the course of about ten minutes, we’ll be reviewing the “preg_match()” and “preg_replace()” functions to validate a form.

Day 7: Regular Expressions

Further Viewing

To learn more about regular expressions, I recommend that you review this introductory screencast that I created months ago.

Download the Source Code

24

Comments
  • Saro says:

    Yay, it’s back on track! Keep it up Jeff!

  • Brenelz says:

    Regular Expressions are really powerful! Jeff only tapped the surface…

  • Srigi says:

    Jeff, there is a small mistake in SC. If you want to designate all numbers, the correct form is ‘0-9′. Also is worth to notice, that using brackets, mean “designate group of characters”.

    BTW thx for SC, good work.

  • Jeffrey says:

    @Srigi – Of course. Why was I leaving off the zero?? :)

  • Phillip Raffnsoe says:

    Hi, Jeff I’m glad you’re well again, and are able to continue this fantastic screencast serie.

    Anyway! Something has been puzzling my mind for months now! What font are you using for the tuts site (and this one)? I’ve used all the font recognition applications I could find, and I’ve dug through several of my own fonts, but I’ve failed!

    Please tell me what font that is, and I’ll be you forever grateful!

  • Jeffrey says:

    @Phillip – It’s called “Agenda”.

  • Meshach says:

    @Jeffery:

    AWESOME!!!!!

  • This is nice, thanks for the tut, will help me with validating forms.

  • welcome back jeff we were waiting yeah :)

  • Yizi says:

    Why screen cast 7? what happened to 5 and 6? hmmm am i missing something?

  • Yizi says:

    Haahah got it mixed up with the wordpress one

  • Wassim says:

    I’ve noticed that you pronounce SQL like I do: SEE’Q'WAL, and just before you finish to pronounce it you update it to be the academic SQL that I don’t like :D Well, Jeff, take it easy; keep it SEE’Q'WA ;-)

    Get well :-)

  • Seanl says:

    Jeff even though reg ex is a very abstract concept I think you explained it very well, certainly better than any book/site I’ve read at least, glad you feeling better keep up the good work………………………

  • Jeffrey says:

    @Wassim – Gotta make everyone happy! I come from an ASP.NET background where you pronounce it that way – SEEQUAL SERVER.

    The PHP crowd prefers MY S Q L.

    Go figure.

  • Mason Sklut says:

    Keep it up Jeff. I’m really happy to see how well these PHP tutorials are going.

    - Mason

  • M.A.Yoosuf says:

    awsome, after one week, pls continue with the OPP series of NETTUTS also pls, thanks

  • Meshach says:

    @M.A.Yoosuf:

    Give him a chance!
    ———————–

    Jeffery,

    I’m sorry you came down with a cold, being sick aint fun.

  • Rob MacKay says:

    @Jeff Thanks! I’ve been looking forward to this! :D

  • ilias says:

    Thanks!
    Glad you’re all better!

  • LiThiuM says:

    Thanks a lot for the Greats tuts Helped me out Getting back on track on PHP. I had left it behind I was not learning properly I guess but you Explain VERY well and I can’t wait for more tuts.

    Glad you are feeling better :)

  • Bryan Kwon says:

    I have been missing this series so much,
    Thank you for coming back!!

  • Mike says:

    Hey Jeff
    Enjoying the tutorials

    FYI when you were modifying your original regular expression and added the dash (hyphen) the reason you got an error is because of where you added the hyphen. You have to be careful where you add that character to the character class. The way you added it, it was try to define a range of characters though that wasn’t what you meant, not the actual character itself. Your range just happened to be a bad one, hence the error. If it had been a good one say you may have matched other characters you didn’t intend and not match the hyphen at all. In general that character needs to either be escaped or the very first or very last character of the character class to avoid it being a range operator.

    If anyone wants a slightly more detailed explanation I went over it here http://regexadvice.com/blogs/mash/archive/2004/06/17/310.aspx

  • Tsalagi says:

    Hello Jeff. Thanks again for this tutorial. Big help in introducing PHP. I’ve read a lot on the net about a but either in PHP or IE with the submit buttons on forms activated by php and I’m experiencing issues with the code. When I load the form in IE7 I have to click the submint button two times to get a response and then it is negative because the first click clears the contents of the text field. In Firefox it works perfect. Can you comment on this issue please?

    Thanks

    Glad your back in the game!

  • Simon says:

    Jeff, your always using cool little shortcuts like creating the form at the beginning of the video. Do you have a reference of the shortcuts you uses anywhere?