Created
October 23, 2013 15:43
-
-
Save gerardorochin/7121126 to your computer and use it in GitHub Desktop.
Translate html minimal code WYSIWYG editor to markdown
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 | |
$wysiwyg = "<p><b>test</b></p><p><i>test</i></p><p><strike>test</strike></p><p><br></p><p><ul><li>test</li></ul></p><p><ol><li>test</li></ol></p>"; | |
$html = array('<b>', '</b>', '<i>', '</i>', '<p>', '</p>', '<br>', '<ul>', '</ul>', '<li>', '</li>', '<ol>', '</ol>', '<strike>', '</strike>'); | |
$markdown = array('**', '**', '*', '*', '', PHP_EOL, PHP_EOL, '', '', "* ", '', '', '', '~~', '~~'); | |
echo str_replace($html, $markdown, $wysiwyg); | |
/** | |
Original: | |
<p><b>test</b></p><p><i>test</i></p><p><strike>test</strike></p><p><br></p><p><ul><li>test</li></ul></p><p><ol><li>test</li></ol></p> | |
Result: | |
**test** | |
*test* | |
~~test~~ | |
* test | |
* test | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment