JFilterOutput/cleanText: Difference between revisions
From Joomla! Documentation
No edit summary |
m removing red link to edit, no existant pages |
||
| Line 3: | Line 3: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
<nowiki>[< | <nowiki>[<! removed edit link to red link >]</nowiki> | ||
</span> | </span> | ||
<! removed transcluded page call, red link never existed > | |||
===Syntax=== | ===Syntax=== | ||
| Line 31: | Line 31: | ||
function cleanText ( &$text ) | function cleanText ( &$text ) | ||
{ | { | ||
$text = preg_replace( "' | $text = preg_replace( "'<script[^>]*>.*?</script>'si", '', $text ); | ||
$text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text ); | $text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text ); | ||
$text = preg_replace( '/<!--.+?-->/', '', $text ); | $text = preg_replace( '/<!--.+?-->/', '', $text ); | ||
| Line 45: | Line 45: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
<nowiki>[< | <nowiki>[<! removed edit link to red link >]</nowiki> | ||
</span> | </span> | ||
<! removed transcluded page call, red link never existed > | |||
===Examples=== | ===Examples=== | ||
| Line 60: | Line 60: | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
[[Category:Archived pages API15]] | |||
Revision as of 01:38, 13 May 2013
Description
Cleans text of all formating and scripting code
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
cleanText(&$text)
| Parameter Name | Default Value | Description |
|---|---|---|
| &$text |
Defined in
libraries/joomla/filter/filteroutput.php
Importing
jimport( 'joomla.filter.filteroutput' );
Source Body
function cleanText ( &$text )
{
$text = preg_replace( "'<script[^>]*>.*?</script>'si", '', $text );
$text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text );
$text = preg_replace( '/<!--.+?-->/', '', $text );
$text = preg_replace( '/{.+?}/', '', $text );
$text = preg_replace( '/ /', ' ', $text );
$text = preg_replace( '/&/', ' ', $text );
$text = preg_replace( '/"/', ' ', $text );
$text = strip_tags( $text );
$text = htmlspecialchars( $text );
return $text;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
<CodeExamplesForm />