-
-
Save steve-ryan/0eb1f6447dcc3f2c4b854eb84b721489 to your computer and use it in GitHub Desktop.
Creating custom markup using PHP
This file contains hidden or 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