<?php
function str_replace_once($needle , $replace , $haystack){
// Looks for the first occurence of $needle in $haystack
// and replaces it with $replace.
$pos = strpos($haystack, $needle);
if ($pos === false) {
// Nothing found
return $haystack;
}
return substr_replace($haystack, $replace, $pos, strlen($needle));
}
$content = "<p>hola1</p> <p>hola2</p>";
print str_replace_once('<p>', '<p class="first">', $content);
?>
el resultat que obtenim és el següent
<p class="first">hola1</p> <p>hola2</p>funció trobada al fòrum
add_filter('the_content', 'first_p_style');
function first_p_style($content) {
$output=str_replace_once('<p>', '<p class="first">', $content);
return ($output);
}
Primer Paràgraf