I have text in a MYSQL database like such:
"2/22/10 - Called Lisa today. She emailed the app.
2/8/10 - No response to previous email. Forwarded again today.
1/27/10 - Emailed Lisa Gregory to see how soon we can start the application process."

The thing I'd like to do is have the date at the beginning of each line formatted so it stands out with either bold, underline, italics.. anything. I realize not every date is the same length - it's no big deal if the dash and spaces are also formatted.

I'm just not sure where to start... preg_replace??

echo "<table border=\"1\" width=\"60%\">

Thanks in advance!

Member Avatar

Sort out your mysql table - it's daft. If you are timestamping / dating entries, there should be a datetime/date/integer field to mark this. It should not be in the main body. Once your sort this out:

Use CSS. Give the date a span tag - possibly with a classname. You can make the span tag a block level element - so it looks like a heading. You can make it bold, italic, underlined, overlined, wombling free, the wombles of Wimbledon... (sorry got carried away)... red and yellow and pink and green, purple and orange and blue. Get a handle on basic CSS and you won't need to bother the good people on the php forum.

If you insist on using the date in the body of the text in a db field, you can use substr() / substr_replace() etc to format/change your output to usable HTML. Hint - date has 8 chars - although you really should use 4 digits for the year.

Found a fix on php.net, of all places, and tweaked it :)

$line = nl2br($Comments);
    $line = preg_replace_callback(
            // single quotes are essential here,
            // or alternative escape all $ as \$
            '; return "<b>".$matches[0]."</b>";'
echo "<table border=\"1\" width=\"60%\">

This bolds all instances of a matching date, but that's fine with me.