Question

I need to clean an html string but I need to keep a custom tagin it , like :

<CUSTOM_TAG/>

I use 'tidy_repair_string()' php function.

$str = '<div><CUSTOM_TAG/><br><span>my little html</span></div>';
$tidy_config = array();
$tidy_text = tidy_repair_string($str, $tidy_config, 'utf8');

I didn't find any Tidy options which can help me. Any idea ?

In advance, Thanks.


I'VE FOUND THE SOLUTION :

The Tidy option you need to use is : " 'input-xml' => true ". Thank you all for your investigation !!

Was it helpful?

Solution

The Tidy option you need to use is : " 'input-xml' => true ". Thank you all for your investigation !!

OTHER TIPS

strip_tags( ) should be able to do what you want. You can give it a list of tags to skip.

Example:

$str = '<div><CUSTOM_TAG/><br><span>my little html</span></div>';
$tidy_text = strip_tags( $str, "<CUSTOM_TAG>" );

You need to teach Tidy that the <CUSTOM_TAG> is valid by specifying the new-blocklevel-tags configuration option. You probably also need to add it to new-empty-tags to make it accept it without content or attributes, it will probably strip it away otherwise.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top