Forum Moderators: coopster
Basically I want the article to automatically be outputed with the first letter of the first Paragraph to be in a slightly larger font with a different color.
Can I accomplish this using the strreplace function in PHP?
Something like this would work though:
$paragraph = 'Here\'s the paragraph text';
// Add the font change to the first char of $paragraph
$first_char = '<font size="3">' . $paragraph[0] . '</font>';
// Combine $first_char and the $paragraph string starting from the second char
$new_paragraph = $first_char . substr($paragraph,1);
$pattern = "/([a-zA-Z])/";
$formatted = preg_replace($pattern,"<font size='10px'>$1</font>",$string,1);
echo $formatted;
Good luck!
I think this pattern will work, but you might want to test it a bit.
$pattern = "/(?<!\<[a-zA-Z1-6])([a-zA-Z0-9])(?![a-zA-Z1-6]*>)/";
Note that this will match the first letter / number outside of a basic html tag, so if the paragraph starts with a quotation mark or something else it may look a little funny. You could modify the regex to include this, but that's a bit harder... :)
The pattern also won't work on tags with attributes, such as <p class="style">
[edited by: MattAU at 12:06 am (utc) on Oct. 9, 2006]