0

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??

<?
$cleancomments=stripslashes($_POST[Comments]);
echo "<table border=\"1\" width=\"60%\">
	<tr><td>Comments</td>
	</tr>
	<tr>
		<td>".nl2br($cleancomments)."</td>
	</tr>
</table>";

Thanks in advance!

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by retareed
0

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.

0

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

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

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.