Created
December 5, 2018 00:14
-
-
Save Eyad-Bereh/9474bd8a3537b56a5eab5905098ca853 to your computer and use it in GitHub Desktop.
Creating custom markup using 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 | |
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(" ", " ", $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