Kevin Pirnie' Articles

I recently worked on a custom CMS project, where one of the requirements was to make the first sentence of each paragraph on each page render bold.While there is no 100% sure-fire way to do this, I found the following very helpful in achieving what I was after.First and Foremost, the function that does the dirty work: function bold_first_sentence($string) { $retStr = ''; preg_match_all('/(?<=[.?!]|^).*?(?=([.?!]).{0,3}[A-Z]|$)/s', $string[1], $matches); $mCt = count($matches[0]) - 1; for($i = 0; $i < $mCt ; ++$i){ if($i === 0){ $retStr .= '<strong>' . trim($matches[0][$i]) . $matches[1][$i] . '</strong> '; }else{ $retStr .= trim($matches[0][$i]).$matches[1][$i] . ' '; } } return '<p>' . $retStr . '</p>'; } Now, since the CMS utilizes classes to render all it's content, we had to make a slight… Read More