Skip a word

3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 10, 2013   (RSS)

By Kenny - April 9, 2013 - edited: April 9, 2013

I want to be a little creative with some CSS and have text that shows the first word in a different color.  I have established two CSS Classes for the colors and divided up the "Title" using the MaxWords script

  function maxWords($textOrHtml, $maxWords) { 
  $text = strip_tags($textOrHtml); 
  $words = preg_split("/\s+/", $text, $maxWords+1); 
  if (count($words) > $maxWords) { unset($words[$maxWords]); } 
  $output = join(' ', $words); 
  return $output; 

and then in the page code

<span class="red-title"><?php echo maxWords($record['title'], 1) ?></span> <span class="black-title"><?php echo htmlencode($record['title']) ?></span>

Now, the problem I face with that is that it shows the first word over again in the second instance.  I am thinking I need to skip the first word of the title in the second instance so my titles show up like this:

Service and Support

Any ideas on how this could be accomplished?

I have tried using (with no luck as this only removes the first letter)

<?php echo substr($record['title'], 1) ?>

By Djulia - April 10, 2013 - edited: April 10, 2013


An example here:

$str = maxWords($record['title'], 10);
$newTitle = explode(" ", trim($str), 2);

$str1 = '<b style="color:red">' . $newTitle[0] . '</b>';

if (isset($newTitle[1])) { $str2 = '<i>' . $newTitle[1] . '</i>'; }
else { $str2 = ''; }

$newTitle = $str1 . $str2;
echo $newTitle;

Hope that helps!