Issue
How can add I HTML tags ( <b> </b>
) to the last word of a string?
The word is different for each result.
Language used : PHP The string is a 1 line string ( the local market of city ) and inserted in a link
echo '<a href="'.$marche_permalink.'">'. $marche_title . '</a> ['. $hdebut .' - '. $hfin .']<br />';
The string is $marche_title
.
Solution
I think the simplest interpretation of your question is this:
$formatted = preg_replace('/\S+$/', '<b>$0</b>', $string);
It will wrap any sequence of non-whitespace characters before the end of the string in the <b>
tag. If there aren't any spaces, it will wrap the entire string in the tag, which should be okay because the entire string is the last word of the string.
Answered By - Don't Panic Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.