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!

What PHP book?
And which examples are they giving that you think can be done with CSS?

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?

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.

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!

You’re welcome :slight_smile: <– another example of regex replacement <– and another one…