Skip to content

Instantly share code, notes, and snippets.

@sumitpore
Created March 21, 2020 06:05
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 sumitpore/04cd35e5b89f8568e5434c8a0b595dc3 to your computer and use it in GitHub Desktop.
Save sumitpore/04cd35e5b89f8568e5434c8a0b595dc3 to your computer and use it in GitHub Desktop.
Example of Replacing Tags using PHP
<?php
/**
* Replaces <i> and <b> tags with <em> and <strong> tags.
*
* @param string $string The input string.
* @return string The filtered text.
*/
function replaceTagsIB($string) {
$pattern = array('`(<b)([^\w])`i', '`(<i)([^\w])`i');
$replacement = array("<strong$2", "<em$2");
$subject = str_replace(array('</b>', '</i>', '</B>', '</I>'), array('</strong>', '</em>', '</strong>', '</em>'), $string);
return preg_replace($pattern, $replacement, $subject);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment