tags:

views:

34

answers:

3

I am printing using PHP

<?php echo $article->link($article->title()); ?>

This string holds something like

"Team Member - Job Title"

What id like to do is wrap everything after the dash in a span so i can change its colour.

Any help would be greatfully appreciated.

A: 

preg_replace is probably the easiest way to do this:

preg_replace('/([^-]*\s*-\s*)(.*)/', '\\1<span class="whatever">\\2</span>', $article->link($article->title()) )
SoapBox
+2  A: 

Try this:

<?php
list($a, $b) = explode(' - ', $article->title());
echo $article->link($a.' - <span>'.$b.'</span>');
?>
Tatu Ulmanen
My mistake, works perfectly thank you.
Andy
A: 

Not elegant, but fast:

$str = 'Team Member - Job Title' . '</span>';
$str = strtr(
    $str,
    '-',
    '- <span>'
);
Tammo
Thanks, this worked also.
Andy