Другие языки программирования и технологии
как убрать теги с помощью str_replace или preg_replace (php)
в результате эти строчки мешают, корректному отображению взять в ковычки не получается, что можно сделать? span style='color:#0033FF' и span style='color:green'
strip_tags()
Медет Ахметов
И думать не надо...
полный код удаления всего ненужного:
function phpdigCleanHtml($text) {
//htmlentities
global $spec;
//replace blank characters by spaces
$text = ereg_replace("[\r\n\t]+"," ",$text);
//extracts title
if (preg_match('/< *title *>(.*?)< *\/ *title *>/is',$text,$regs)) {
$title = trim($regs[1]);
}
else {
$title = "";
}
//delete content of head, script, and style tags
$text = eregi_replace("<head[^>]*>.*</head>"," ",$text);
//$text = eregi_replace("<script[^>]*>.*</script>"," ",$text); // more conservative
$text = preg_replace("/<script[^>]*?>.*?<\/script>/is"," ",$text); // less conservative
$text = eregi_replace("<style[^>]*>.*</style>"," ",$text);
// clean tags
$text = preg_replace("/<[\/\!]*?[^<>]*?>/is"," ",$text);
//$text = strip_tags($text,"<sub>");
// first case-sensitive and then case-insensitive
//tries to replace htmlentities by ascii equivalent
foreach ($spec as $entity => $char) {
$text = ereg_replace ($entity."[;]?",$char,$text);
$title = ereg_replace ($entity."[;]?",$char,$title);
}
//tries to replace htmlentities by ascii equivalent
foreach ($spec as $entity => $char) {
$text = eregi_replace ($entity."[;]?",$char,$text);
$title = eregi_replace ($entity."[;]?",$char,$title);
}
while (eregi('([0-9]{3});',$text,$reg)) {
$text = str_replace($reg[0],chr($reg[1]),$text);
}
while (eregi('([a-f0-9]{2});',$text,$reg)) {
$text = str_replace($reg[0],chr(base_convert($reg[1],16,10)),$text);
}
//replace foo characters by space
$text = eregi_replace("[*{}()\"\r\n\t]+"," ",$text);
$text = eregi_replace("<[^>]*>"," ",$text);
$text = ereg_replace("(\r|\n|\r\n)"," ",$text);
// replace any stranglers by space
$text = eregi_replace("( -> | <- | > | < )"," ",$text);
//strip characters used in highlighting with no space
$text = str_replace("^#_","",str_replace("_#^","",$text));
$text = str_replace("@@@","",str_replace("@#@","",$text));
$text = ereg_replace("[[:space:]]+"," ",$text);
$retour['content'] = $text;
$retour['title'] = $title;
return $retour;
}
function phpdigCleanHtml($text) {
//htmlentities
global $spec;
//replace blank characters by spaces
$text = ereg_replace("[\r\n\t]+"," ",$text);
//extracts title
if (preg_match('/< *title *>(.*?)< *\/ *title *>/is',$text,$regs)) {
$title = trim($regs[1]);
}
else {
$title = "";
}
//delete content of head, script, and style tags
$text = eregi_replace("<head[^>]*>.*</head>"," ",$text);
//$text = eregi_replace("<script[^>]*>.*</script>"," ",$text); // more conservative
$text = preg_replace("/<script[^>]*?>.*?<\/script>/is"," ",$text); // less conservative
$text = eregi_replace("<style[^>]*>.*</style>"," ",$text);
// clean tags
$text = preg_replace("/<[\/\!]*?[^<>]*?>/is"," ",$text);
//$text = strip_tags($text,"<sub>");
// first case-sensitive and then case-insensitive
//tries to replace htmlentities by ascii equivalent
foreach ($spec as $entity => $char) {
$text = ereg_replace ($entity."[;]?",$char,$text);
$title = ereg_replace ($entity."[;]?",$char,$title);
}
//tries to replace htmlentities by ascii equivalent
foreach ($spec as $entity => $char) {
$text = eregi_replace ($entity."[;]?",$char,$text);
$title = eregi_replace ($entity."[;]?",$char,$title);
}
while (eregi('([0-9]{3});',$text,$reg)) {
$text = str_replace($reg[0],chr($reg[1]),$text);
}
while (eregi('([a-f0-9]{2});',$text,$reg)) {
$text = str_replace($reg[0],chr(base_convert($reg[1],16,10)),$text);
}
//replace foo characters by space
$text = eregi_replace("[*{}()\"\r\n\t]+"," ",$text);
$text = eregi_replace("<[^>]*>"," ",$text);
$text = ereg_replace("(\r|\n|\r\n)"," ",$text);
// replace any stranglers by space
$text = eregi_replace("( -> | <- | > | < )"," ",$text);
//strip characters used in highlighting with no space
$text = str_replace("^#_","",str_replace("_#^","",$text));
$text = str_replace("@@@","",str_replace("@#@","",$text));
$text = ereg_replace("[[:space:]]+"," ",$text);
$retour['content'] = $text;
$retour['title'] = $title;
return $retour;
}
Похожие вопросы
- Почему php-код( т. е. теги кода) выводится в браузере, а не исполняется?
- Как на PHP получать пути к файлам из массива names в теге input при загрузке некольких файлов?
- while(!((str[i]>='0'&&str[i]<='9')||str[i]=='\0')) как перевести на человеческий язык это условие? - Язык си
- Не выходит получить страницу с помощью cUrl PHP .
- Нет перегруженной подпрограммы с таким количеством параметров Replace
- Изучил HTML,с ним всё ясно:каждый тег делает своё дело.А с CSS,PHP и Java Script проблемы.
- нужна помощь в написани php кода для создания авторизации пользователя и регистрации
- Какой нужен тег или скрипт
- html и тег h1
- Вопрос к сайто- строителям, что за теги <noindex> и зачем ими закрывать внешние ссылки?