Created
August 15, 2016 17:58
-
-
Save bohnna/1aeb805862e0240c77e1a1375977cfd1 to your computer and use it in GitHub Desktop.
Wrap a span tag around all instances in a string that are surrounded by 4 asterisks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static function span_strings($string, $class = null) { | |
| /* Takes a string, and surrounds anything surrounded by 4 asterisks with | |
| * a span tag with an optional class name. | |
| * | |
| * If a class is specified in the second argument, it will add | |
| * a class to the span tag. | |
| */ | |
| $match_phrase = "/\*\*([^**]*)\*\*/"; | |
| $replace_string = '<span'; | |
| $replace_string .= $class ? ' class="' . $class . '">' : '>'; | |
| $replace_string .= '${1}</span>'; | |
| $new_string = preg_replace($match_phrase, $replace_string, $string); | |
| return $new_string; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment