SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    May 2011
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regular Functions in the real world

    Hi there,

    I have been working my way through the PHP book and have got to the chapter on formatting with regular expressions.

    I'm slightly confused. Doesn't CSS do everything that regular expressions can do?

    If not then some examples would be useful.

    Thanks for your time and help!

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    What PHP book?
    And which examples are they giving that you think can be done with CSS?

  3. #3
    SitePoint Member
    Join Date
    May 2011
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BUILD YOUR OWN DATABASE DRIVEN WEB SITE USING PHP & MYSQL
    BY KEVIN YANK
    4TH EDITION

    Below is a quote from one of the opening paragraphs in the chapter:

    On any but the simplest of web sites, it will be necessary to allow content (in our
    case study, jokes) to include some sort of formatting. In a simple case, this might
    merely be the ability to break text into paragraphs. Often, however, content providers
    will expect facilities such as bold or italic text, hyperlinks, and so on.
    Since this book does not cover CSS, I am wondering is this chapter for people who want to produce some simple formatting rather then having to learn CSS?

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    I looked it up. Chapter 8, right?

    If you read through that chapter, you'll see the author isn't really using regex to "format" the content in the way CSS does. What he does is create a bbcode parser. As explained in the book, bbcode is used in forums to give the users a simple means to add some formatting to the things they write, using bbcode tags.
    But since browser don't understand bbcode, these tags have to be replaced by valid html before outputting the content to the user.

    It's this replacing that is done using regex.

    The way the final html code is formatted will depend as always on your CSS.

    Another common use for regex is validation of user input.

  5. #5
    SitePoint Member
    Join Date
    May 2011
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, I see.

    I guess with the website I am building I am going to style all the content using CSS myself, the user will not have a choice mainly because they do not need to, but I can see as with something like this forum why it would be good to give the user an opportunity to format their text <<< not particularly a good example!

    Thanks very much for your help and speed of reply!

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    You're welcome <-- another example of regex replacement <-- and another one...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •