Example
<p>Lorem ipsum dolor sit amet</p>
<p>Morbi elementum odio vel tortor adipiscing vel tempor risus ullamcorper.</p>
I want add class for first paragraph and add span class to the first letter
<p class="first-paragraph"><span class="first-letter">L</span>orem ipsum dolor sit amet</p>
Let me know how can be with PHP
$text = '<p>Lorem ipsum dolor sit amet</p>
<p>Morbi elementum odio vel tortor adipiscing vel tempor risus ullamcorper.</p>';
$text = substr_replace($text, '</span>', 4, 0);
$text = substr_replace($text, '<span class="first-letter">', 3, 0);
$text = substr_replace($text, ' class="first-paragraph"', 2, 0);
echo htmlspecialchars($text);
:-)
You can make use of pure CSS3:
p:first-of-type {
color: red;
}
p:first-of-type::first-letter {
color: blue;
font-size: x-large;
}
fiddle here: http://jsfiddle.net/everton/vpcey/