johnnyutah1980 — 2012-01-11T07:18:12-05:00 — #1
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!
guido2004 — 2012-01-11T07:21:56-05:00 — #2
What PHP book?
And which examples are they giving that you think can be done with CSS?
johnnyutah1980 — 2012-01-11T07:26:13-05:00 — #3
BUILD YOUR OWN DATABASE DRIVEN WEB SITE USING PHP & MYSQL
BY KEVIN YANK
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?
guido2004 — 2012-01-11T07:38:11-05:00 — #4
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.
johnnyutah1980 — 2012-01-11T09:15:58-05:00 — #5
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!
guido2004 — 2012-01-11T09:24:25-05:00 — #6
You're welcome <-- another example of regex replacement <-- and another one...