Skip to content

Instantly share code, notes, and snippets.

@gerardorochin
Created October 23, 2013 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerardorochin/7121126 to your computer and use it in GitHub Desktop.
Save gerardorochin/7121126 to your computer and use it in GitHub Desktop.
Translate html minimal code WYSIWYG editor to markdown
<?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