当前位置: 首页>>代码示例>>PHP>>正文


PHP clsTinyButStrong::f_Xml_FindNewLine方法代码示例

本文整理汇总了PHP中clsTinyButStrong::f_Xml_FindNewLine方法的典型用法代码示例。如果您正苦于以下问题:PHP clsTinyButStrong::f_Xml_FindNewLine方法的具体用法?PHP clsTinyButStrong::f_Xml_FindNewLine怎么用?PHP clsTinyButStrong::f_Xml_FindNewLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在clsTinyButStrong的用法示例。


在下文中一共展示了clsTinyButStrong::f_Xml_FindNewLine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: f_Xml_FindTag

 static function f_Xml_FindTag(&$Txt, $Tag, $Opening, $PosBeg, $Forward, $LevelStop, $WithPrm, $WithPos = false)
 {
     /* This function is a smart solution to find an XML tag.
     It allows to ignore full opening/closing couple of tags that could be inserted before the searched tag.
     It allows also to pass a number of encapsulations.
     To ignore encapsulation and opengin/closing just set $LevelStop=false.
     */
     if ($Tag === '_') {
         // New line
         $p = clsTinyButStrong::f_Xml_FindNewLine($Txt, $PosBeg, $Forward, $LevelStop !== 0);
         $Loc = new clsTbsLocator();
         $Loc->PosBeg = $Forward ? $PosBeg : $p;
         $Loc->PosEnd = $Forward ? $p : $PosBeg;
         $Loc->RightLevel = 0;
         return $Loc;
     }
     $Pos = $PosBeg + ($Forward ? -1 : +1);
     $TagIsOpening = false;
     $TagClosing = '/' . $Tag;
     $LevelNum = 0;
     $TagOk = false;
     $PosEnd = false;
     $TagL = strlen($Tag);
     $TagClosingL = strlen($TagClosing);
     $RightLevel = 0;
     do {
         // Look for the next tag def
         if ($Forward) {
             $Pos = strpos($Txt, '<', $Pos + 1);
         } else {
             if ($Pos <= 0) {
                 $Pos = false;
             } else {
                 $Pos = strrpos(substr($Txt, 0, $Pos - 1), '<');
                 // strrpos() syntax compatible with PHP 4
             }
         }
         if ($Pos !== false) {
             // Check the name of the tag
             if (strcasecmp(substr($Txt, $Pos + 1, $TagL), $Tag) == 0) {
                 $PosX = $Pos + 1 + $TagL;
                 // The next char
                 $TagOk = true;
                 $TagIsOpening = true;
             } elseif (strcasecmp(substr($Txt, $Pos + 1, $TagClosingL), $TagClosing) == 0) {
                 $PosX = $Pos + 1 + $TagClosingL;
                 // The next char
                 $TagOk = true;
                 $TagIsOpening = false;
             }
             if ($TagOk) {
                 // Check the next char
                 $x = $Txt[$PosX];
                 if ($x === ' ' or $x === "\r" or $x === "\n" or $x === '>' or $Tag === '/' or $Tag === '') {
                     // Check the encapsulation count
                     if ($LevelStop === false) {
                         // No encaplusation check
                         if ($TagIsOpening !== $Opening) {
                             $TagOk = false;
                         }
                     } else {
                         // Count the number of level
                         if ($TagIsOpening) {
                             $PosEnd = strpos($Txt, '>', $PosX);
                             if ($PosEnd !== false) {
                                 if ($Txt[$PosEnd - 1] === '/') {
                                     if ($Pos < $PosBeg and $PosEnd > $PosBeg) {
                                         $RightLevel = 1;
                                         $LevelNum++;
                                     }
                                 } else {
                                     $LevelNum++;
                                 }
                             }
                         } else {
                             $LevelNum--;
                         }
                         // Check if it's the expected level
                         if ($LevelNum != $LevelStop) {
                             $TagOk = false;
                             $PosEnd = false;
                         }
                     }
                 } else {
                     $TagOk = false;
                 }
             }
             //--> if ($TagOk)
         }
     } while ($Pos !== false and $TagOk === false);
     // Search for the end of the tag
     if ($TagOk) {
         $Loc = new clsTbsLocator();
         if ($WithPrm) {
             clsTinyButStrong::f_Loc_PrmRead($Txt, $PosX, true, '\'"', '<', '>', $Loc, $PosEnd, $WithPos);
         } elseif ($PosEnd === false) {
             $PosEnd = strpos($Txt, '>', $PosX);
             if ($PosEnd === false) {
                 $TagOk = false;
             }
//.........这里部分代码省略.........
开发者ID:prolin99,项目名称:mobile_view,代码行数:101,代码来源:tbs_class_php5.php

示例2: f_Xml_FindTag

function f_Xml_FindTag(&$Txt,$Tag,$Opening,$PosBeg,$Forward,$LevelStop,$WithPrm) {
/* This function is a smarter issue to find an HTML tag.
It enables to ignore full opening/closing couple of tag that could be inserted before the searched tag.
It also enables to pass a number of encapsulations.
To ignore encapsulation and opengin/closing just set $LevelStop=false.
*/

	if ($Tag==='_') { // New line
		$p = clsTinyButStrong::f_Xml_FindNewLine($Txt,$PosBeg,$Forward,($LevelStop!==0));
		$Loc = new clsTbsLocator;
		$Loc->PosBeg = ($Forward) ? $PosBeg : $p;
		$Loc->PosEnd = ($Forward) ? $p : $PosBeg;
		return $Loc;
	}

	$Pos = $PosBeg + (($Forward) ? -1 : +1);
	$TagIsOpening = false;
	$TagClosing = '/'.$Tag;
	$LevelNum = 0;
	$TagOk = false;

	do {

		// Look for the next tag def
		if ($Forward) {
			$Pos = strpos($Txt,'<',$Pos+1);
		} else {
			if ($Pos<=0) {
				$Pos = false;
			} else {
				$Pos = strrpos(substr($Txt,0,$Pos - 1),'<');
			}
		}

		if ($Pos!==false) {

			// Check the name of the tag
			if (strcasecmp(substr($Txt,$Pos+1,mb_strlen($Tag)),$Tag)==0) {
				$PosX = $Pos + 1 + mb_strlen($Tag); // The next char
				$TagOk = true;
				$TagIsOpening = true;
			} elseif (strcasecmp(substr($Txt,$Pos+1,mb_strlen($TagClosing)),$TagClosing)==0) {
				$PosX = $Pos + 1 + mb_strlen($TagClosing); // The next char
				$TagOk = true;
				$TagIsOpening = false;
			}

			if ($TagOk) {
				// Check the next char
				$x = $Txt[$PosX];
				if (($x===' ') or ($x==="\r") or ($x==="\n") or ($x==='>')) {
					// Check the encapsulation count
					if ($LevelStop===false) { // No encaplusation check
						if ($TagIsOpening!==$Opening) $TagOk = false;
					} else { // Count the number of level
						if ($TagIsOpening) {
							$LevelNum++;
						} else {
							$LevelNum--;
						}
						// Check if it's the expected level
						if ($LevelNum!=$LevelStop) $TagOk = false;
					}
				} else {
					$TagOk = false;
				}
			} //--> if ($TagOk)

		}
	} while (($Pos!==false) and ($TagOk===false));

	// Search for the end of the tag
	if ($TagOk) {
		$Loc = new clsTbsLocator;
		if ($WithPrm) {
			$PosEnd = 0;
			clsTinyButStrong::f_Loc_PrmRead($Txt,$PosX,true,'\'"','<','>',$Loc,$PosEnd);
		} else {
			$PosEnd = strpos($Txt,'>',$PosX);
			if ($PosEnd===false) {
				$TagOk = false;
			}
		}
	}

	// Result
	if ($TagOk) {
		$Loc->PosBeg = $Pos;
		$Loc->PosEnd = $PosEnd;
		return $Loc;
	} else {
		return false;
	}

}
开发者ID:rhertzog,项目名称:lcs,代码行数:95,代码来源:tinyButStrong.class.php


注:本文中的clsTinyButStrong::f_Xml_FindNewLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。