Skip to content

Instantly share code, notes, and snippets.

@Eyad-Bereh
Created December 5, 2018 00:14
Show Gist options
  • Save Eyad-Bereh/9474bd8a3537b56a5eab5905098ca853 to your computer and use it in GitHub Desktop.
Save Eyad-Bereh/9474bd8a3537b56a5eab5905098ca853 to your computer and use it in GitHub Desktop.
Creating custom markup using PHP
<?php
function string_to_html(string $str) {
$str = str_ireplace("[newline]", "<br/>", $str);
$str = str_ireplace("[bold]", "<b>", $str);
$str = str_ireplace("[/bold]", "</b>", $str);
$str = str_ireplace("[italic]", "<i>", $str);
$str = str_ireplace("[/italic]", "</i>", $str);
$str = str_ireplace("[center]", "<span style=\"text-align:center;\">", $str);
$str = str_ireplace("[/center]", "</span>", $str);
$str = str_ireplace("[left]", "<span style=\"text-align:left;\">", $str);
$str = str_ireplace("[/left]", "</span>", $str);
$str = str_ireplace("[right]", "<span style=\"text-align:right;\">", $str);
$str = str_ireplace("[/right]", "</span>", $str);
$str = str_ireplace("[header]", "<span style=\"text-align:left;\">", $str);
$str = str_ireplace("[/left]", "</span>", $str);
$str = str_ireplace(" ", "&nbsp;", $str);
return $str;
}
echo string_to_html("[bold]Hello
World[/bold]");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment