Skip to content

Instantly share code, notes, and snippets.

@samin
Created August 10, 2012 14:11
Show Gist options
  • Save samin/3314475 to your computer and use it in GitHub Desktop.
Save samin/3314475 to your computer and use it in GitHub Desktop.
Word wrap
<?php
$string = "Lorem ipsum dolor sit amet, <a href=\"#\">consectetuer adipiscing</a> elit, <strong>tincidunt</strong> ut volutpat.";
$content = "";
$words = preg_split('/\s+/', trim($string));
foreach ($words as $word) {
$content .= '<span>'.$word.'</span>';
}
echo $content;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment