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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.