Created
September 5, 2013 10:59
-
-
Save JulianLaval/6448711 to your computer and use it in GitHub Desktop.
Simple function to parse inline Markdown links to HTML.
This file contains 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
<?php | |
// PARSE INLINE MARKDOWN LINKS | |
function markdown_links($x) { | |
preg_match_all('/\[(.*?)\]\((.*?)\)/', $x, $matches); | |
if(!empty($matches)){ | |
foreach($matches[0] as $key => $match){ | |
$x_replace = '<a href="'.$matches[2][$key].'" target="_blank">'.$matches[1][$key].'</a>'; | |
$x = str_replace($matches[0][$key], $x_replace, $x); | |
} | |
} | |
return $x; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: