note 44987 added to function.strip-tags

From: Date: Sun, 22 Aug 2004 16:24:59 +0000
Subject: note 44987 added to function.strip-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-75117@lists.php.net to get a copy of this message
Be aware that tags constitute visual whitespace, so stripping may leave the resulting text looking misjoined. For example, "<strong>This is a bit of text</strong><p />Followed by this bit" are seperable paragraphs on a visual plane, but if simply stripped of tags will result in "This is a bit of textFollowed by this bit" which may not be what you want, e.g. if you are creating an excerpt for an RSS description field. The workaround is to force whitespace prior to stripping, using something like this: $text = getTheText(); $text = preg_replace('/</',' <',$text); $text = preg_replace('/>/','> ',$text); $desc = html_entity_decode(strip_tags($text)); $desc = preg_replace('/[\n\r\t]/',' ',$desc); $desc = preg_replace('/ /',' ',$desc); ---- Manual Page -- http://www.php.net/manual/en/function.strip-tags.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44987 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44987&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44987&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#75117) next »