Skip to content

Instantly share code, notes, and snippets.

@cmd05
Last active March 23, 2022 16:54
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 cmd05/fe70e36523396a0e15febe4a73b2467e to your computer and use it in GitHub Desktop.
Save cmd05/fe70e36523396a0e15febe4a73b2467e to your computer and use it in GitHub Desktop.
<?php
if(isset($_POST['txt'])) {
$value = $_POST['txt'];
}
$newtxt = preg_replace('#\*{2}(.*?)\*{2}#', '<b>$1</b>', $value); //bold **something**
$newtxt = preg_replace('#\_{2}(.*?)\_{2}#', '<i>$1</i>', $newtxt); //italics __something__
$newtxt = preg_replace('#\`{2}(.*?)\`{2}#', '<img src = "$1">', $newtxt); //image ``something.jpg/png``
$newtxt = preg_replace('#\-{2}(.*?)\-{2}#', '<br>', $newtxt); //break line ----
echo $newtxt;
echo "<br> Source code: " . htmlspecialchars($newtxt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment