Forums / Developer / Operator to strip off HTML tags

Operator to strip off HTML tags

Author Message

Piotr Switkowski

Tuesday 18 May 2004 8:56:59 am

Does anyone know any method (probably template operator) to remove HTML formatting from the string (attribute value). I would like to display ezXML field as normal plain text and now I can not see operator that is doing this.

Regards

Dominik Pich

Tuesday 18 May 2004 9:58:01 am

|wash !?

Piotr Switkowski

Wednesday 19 May 2004 6:52:27 am

This is not what I need. Wash only removes "bogus" characters (eq. replaces &reg; registered trademark with with &amp;reg; that do not display corrextly at all). However I need operator to remove normal HTML tags, eq "<p>". If someone have one - I will be gratefull

Paul Borgermans

Wednesday 19 May 2004 7:04:58 am

In template.ini(.append.php)
add under

[PHP]
....
PHPOperatorList[striptags]=strip_tags
......

Then in your template use

$yourstring_with_xml|striptags

and catch the stripped output

A fuller example in the packt ez publish book available later this month

hth

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Paul Wilson

Wednesday 19 December 2007 9:26:02 pm

Hi,

In case anyone needs it, here's a quick and dirty template-based method for stripping HTML tags from an XML field.

The code takes an article (intro) XML and strips out any "<" and ">" and the text in between.

    {def $child_intro_raw=$child.data_map.intro.data_text}
    {def $child_intro=""}
    {def $split_string=$child_intro_raw|explode("<")}

    {foreach $split_string as $this_string_part}
	    {def $sub_string=$this_string_part|explode(">")}
	    {set $child_intro=$child_intro|append($sub_string[1])}
	    {undef $sub_string}
    {/foreach}
{* display result *}
<a title="{$child_intro}" href={$child.url_alias|ezurl}>{$child.name|wash()}</a>

It may fail if there are any < or > symbols in the text.

If you wanted to strip out a particular tag, it may be possible to change the first to explode function to something like, say, {def $split_string=$child_intro_raw|explode("<p")}

You may find that there are blank lines before the basic text you actually want. To get rid of this, change the code above with the if condition shown below.

    {foreach $split_string as $this_string_part}
	    {def $sub_string=$this_string_part|explode(">")}
	    {if ne($sub_string[1]|count_words(),0)}
		    {set $child_intro=$child_intro|append($sub_string[1])}
	    {/if}
	    {undef $sub_string}
    {/foreach}

- Paul

Xavier Dutoit

Thursday 20 December 2007 12:15:55 am

Hi,

have a look at http://projects.ez.no/xmlwash it contains an operator that strips the tags (or only keep some, eg b and i...)

http://www.sydesy.com

eZ debug

Timing: Jan 18 2025 19:16:49
Script start
Timing: Jan 18 2025 19:16:49
Module start 'content'
Timing: Jan 18 2025 19:16:49
Module end 'content'
Timing: Jan 18 2025 19:16:49
Script end

Main resources:

Total runtime0.8633 sec
Peak memory usage4,096.0000 KB
Database Queries209

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 588.8438180.8359
Module start 'content' 0.00560.6928 769.6797691.5703
Module end 'content' 0.69840.1646 1,461.2500337.0625
Script end 0.8630  1,798.3125 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00500.5787210.0002
Check MTime0.00180.2032210.0001
Mysql Total
Database connection0.00070.077110.0007
Mysqli_queries0.774289.68582090.0037
Looping result0.00230.27182070.0000
Template Total0.834496.720.4172
Template load0.00280.321520.0014
Template processing0.831696.336220.4158
Template load and register function0.00020.025210.0002
states
state_id_array0.00170.198110.0017
state_identifier_array0.00130.154620.0007
Override
Cache load0.00240.2775380.0001
Sytem overhead
Fetch class attribute can translate value0.00310.354560.0005
Fetch class attribute name0.00120.144390.0001
XML
Image XML parsing0.00240.273960.0004
class_abstraction
Instantiating content class attribute0.00000.002090.0000
General
dbfile0.00260.3026400.0001
String conversion0.00000.000830.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 24
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs