Source for file class.string_tags.php
Documentation is available at class.string_tags.php
/****************************************************************************
* Software: Tag Extraction Class
* extracts the tags and corresponding text from a string
* Author: Bintintan Andrei, <andy@interpid.eu>
* Last Modification: 2007/12/07
* License: Free for Non Commercial use.
* You may not sell or use this class in a Commercial Project without written permission from the Author.
* If you like my work please DONATE!!! **** paypal@interpid.eu *****
* For more classes visit ***** www.interpid.eu *****
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR “AS IS” AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* PLEASE REPORT ANY BUGS TO THE AUTHOR.
* Extracts the tags and corresponding text from a string
* @author Bintintan Andrei <andy@interpid.eu>
* Contains the Tag/String Correspondence
* Contains the links for the tags that have specified this parameter
* The maximum number of chars for a tag
* @param numeric $p_tagmax - the number of characters allowed in a tag
* Returns TRUE if the specified tag name is an "<open tag>", (it is not already opened)
* @param string $p_tag - tag name
* @param array $p_array - tag arrays
protected function OpenTag($p_tag, $p_array){
if (!eregi("^<([a-zA-Z1-9]{1,$maxElem}) *(.*)>$", $p_tag, $reg)) return false;
preg_match_all("|([^ ]*)=[\"'](.*)[\"']|U", $reg[2], $out, PREG_PATTERN_ORDER);
for ($i=
0; $i<
count($out[0]); $i++
){
array_push($sHREF, array($out[1][$i], $out[2][$i]));
if (in_array($p_tag, $aTAGS)) return false;//tag already opened
/** returnes true if $p_tag is a "<close tag>"
@param $p_tag - tag string
* Returns true if $p_tag is a "<close tag>"
* @param sting $p_tag - tag name
* @param array $p_array - tag array
protected function CloseTag($p_tag, $p_array){
if (!ereg("^</([a-zA-Z1-9]{1,$maxElem})>$", $p_tag, $reg)) return false;
* Expands the paramteres that are kept in Href field
* @param array of parameters
* @return string with concatenated results
* Expands the paramteres that are kept in Href field
$aTmp =
$pResult['params'];
for ($i=
0; $i<
count($aTmp); $i++
){
$pResult[$aTmp[$i][0]] =
$aTmp[$i][1];
unset
($pResult['params']);
* Optimizes the result of the tag result array
* In the result array there can be strings that are consecutive and have the same tag, they
* @param array $result - the array that has to be optimized
* @return array - optimized result
if (count($result) ==
0) return $result;
while ($i <
count($result)){
//if they have the same tag then we concatenate them
if (($current['tag'] ==
$result[$i]['tag']) &&
($current['params'] ==
$result[$i]['params'])){
$current['text'] .=
$result[$i]['text'];
/** Parses a string and returnes the result
* Parses a string and returnes an array of TAG - SRTING correspondent array
* The result has the following structure:
* @param string $p_str - the Input String
* @return array - the result array
$reg =
preg_split('/(<.*>)/U', $p_str, -
1, PREG_SPLIT_DELIM_CAPTURE);
while (list
($key, $val) =
each($reg)) {
if ($val ==
"") continue;
$sTAG =
(($temp =
end($aTAGS)) !=
NULL) ?
$temp :
"";
$sHREF =
(($temp =
end($aHREF)) !=
NULL) ?
$temp :
"";
$sTAG =
(($temp =
end($aTAGS)) !=
NULL) ?
$temp :
"";
$sHREF =
(($temp =
end($aHREF)) !=
NULL) ?
$temp :
"";
array_push($result, array('text'=>
$val, 'tag'=>
$sTAG, 'params'=>
$sHREF));
Documentation generated on Wed, 04 Feb 2009 22:01:34 +0100 by phpDocumentor 1.4.0a2