Skip to content

Instantly share code, notes, and snippets.

@Flyingmana
Created January 27, 2014 11:04
Show Gist options
  • Save Flyingmana/8646722 to your computer and use it in GitHub Desktop.
Save Flyingmana/8646722 to your computer and use it in GitHub Desktop.
<?php
error_reporting(-1);
function magento_removeTags($html){
$html = @preg_replace("# <(?![/a-z]) | (?<=\s)>(?![a-z]) #exi", "htmlentities('$0')", $html);
$html = strip_tags($html);
return htmlspecialchars_decode($html);
}
function magento_removeTags_fixed($html){
$html = preg_replace_callback(
"# <(?![/a-z]) | (?<=\s)>(?![a-z]) #xi",
function($html){ return htmlentities($html[0]); },
$html
);
$html = strip_tags($html);
return htmlspecialchars_decode($html);
}
$testCases = array(
"default store name",
"<div>default store name</div>",
"<div>default store name<div>",
"</a>default store name<>",
);
foreach($testCases as $case){
echo magento_removeTags($case).PHP_EOL;
echo magento_removeTags_fixed($case).PHP_EOL;
echo '#########'.PHP_EOL;
}
echo PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment