Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztextinputparser.php
Go to the documentation of this file.
1 <?php
16 class eZTextInputParser
17 {
18 const CHUNK_TEXT = 1;
19 const CHUNK_TAG = 2;
20
25 function parseText( $text )
26 {
27 $returnArray = array();
28 $pos = 0;
29
30
31 while ( $pos < strlen( $text ) )
32 {
33 // find the next tag
34 $tagStart = strpos( $text, "<", $pos );
35
36 if ( $tagStart !== false )
37 {
38 if ( ( $tagStart - $pos ) >= 1 )
39 {
40 $textChunk = substr( $text, $pos, $tagStart - $pos );
41 $pos += $tagStart - $pos;
42
43
44 if ( strlen( trim( $textChunk ) ) != 0 )
45 {
46 $returnArray[] = array( "Type" => eZTextInputParser::CHUNK_TEXT,
47 "Text" => $textChunk,
48 "TagName" => "#text" );
49
50 eZDebug::writeNotice( $textChunk, "New text chunk in input" );
51 }
52 }
53 // get the tag
54 $tagEnd = strpos( $text, ">", $pos );
55 $tagChunk = substr( $text, $pos, $tagEnd - $pos + 1 );
56 $tagName = preg_replace( "#^<(.+)?(\s.*|>)#m", "\\1", $tagChunk );
57
58 // check for end tag
59 if ( $tagName[0] == "/" )
60 {
61 print( "endtag" );
62 }
63
64 $returnArray[] = array( "Type" => eZTextInputParser::CHUNK_TAG,
65 "TagName" => $tagName,
66 "Text" => $tagChunk,
67 );
68
69 $pos += $tagEnd - $pos;
70 eZDebug::writeNotice( $tagChunk, "New tag chunk in input" );
71 }
72 else
73 {
74
75 // just plain text in the rest
76 $textChunk = substr( $text, $pos, strlen( $text ) );
77 eZDebug::writeNotice( $textChunk, "New text chunk in input" );
78
79 if ( strlen( trim( $textChunk ) ) != 0 )
80 {
81 $returnArray[] = array( "Type" => eZTextInputParser::CHUNK_TEXT,
82 "Text" => $textChunk,
83 "TagName" => "#text" );
84 }
85
86 $pos = strlen( $text );
87 }
88
89 $pos++;
90 }
91 return $returnArray;
92 }
93
95 public $TagStack = array();
96
98 public $InlineTags = array( "emphasize", "strong" );
99
101 public $BreakTags = array();
102 }
103
104 ?>
eZDebug\writeNotice
static writeNotice( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:459
eZTextInputParser
Definition: eztextinputparser.php:17
eZTextInputParser\$TagStack
$TagStack
Contains the tags found.
Definition: eztextinputparser.php:95
eZTextInputParser\CHUNK_TAG
const CHUNK_TAG
Definition: eztextinputparser.php:19
eZTextInputParser\parseText
parseText( $text)
Definition: eztextinputparser.php:25
eZTextInputParser\$BreakTags
$BreakTags
The tags that break the paragraph.
Definition: eztextinputparser.php:101
eZTextInputParser\CHUNK_TEXT
const CHUNK_TEXT
Definition: eztextinputparser.php:18
eZTextInputParser\$InlineTags
$InlineTags
The tags that don't break the text.
Definition: eztextinputparser.php:98
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.