Last active
September 22, 2024 22:37
-
-
Save vijinho/3d66fab3270fc377b8485387ce7e7455 to your computer and use it in GitHub Desktop.
Escape markdown in php
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 | |
/** | |
* Escape markdown text | |
* | |
* @param string $text the markdown text to escape | |
* | |
* @return string escaped text | |
*/ | |
function markdown_escape($text) { | |
return str_replace([ | |
'\\', '-', '#', '*', '+', '`', '.', '[', ']', '(', ')', '!', '&', '<', '>', '_', '{', '}', '|'], [ | |
'\\\\', '\-', '\#', '\*', '\+', '\`', '\.', '\[', '\]', '\(', '\)', '\!', '\&', '\<', '\>', '\_', '\{', '\}', '\|', | |
], $text); | |
} |
Lol, I can't believe people still use my stuff, not coded for over a year. OK added a pipe!
Lol, I can't believe people still use my stuff, not coded for over a year. OK added a pipe!
Thank you, also used it
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be good to add the pipe ( | ) to your list. Otherwise great and thank you!