コード例 #1
0
 static function f_Xml_AttFind(&$Txt, &$Loc, $Move = false, $AttDelim = false)
 {
     // att=div#class ; att=((div))#class ; att=+((div))#class
     $Att = $Loc->PrmLst['att'];
     $p = strrpos($Att, '#');
     if ($p === false) {
         $TagLst = '';
     } else {
         $TagLst = substr($Att, 0, $p);
         $Att = substr($Att, $p + 1);
     }
     $Forward = substr($TagLst, 0, 1) === '+';
     if ($Forward) {
         $TagLst = substr($TagLst, 1);
     }
     $TagLst = explode('+', $TagLst);
     $iMax = count($TagLst) - 1;
     $WithPrm = false;
     $LocO =& $Loc;
     foreach ($TagLst as $i => $Tag) {
         $LevelStop = false;
         while (strlen($Tag) > 1 and substr($Tag, 0, 1) === '(' and substr($Tag, -1, 1) === ')') {
             if ($LevelStop === false) {
                 $LevelStop = 0;
             }
             $LevelStop++;
             $Tag = trim(substr($Tag, 1, strlen($Tag) - 2));
         }
         if ($i == $iMax) {
             $WithPrm = true;
         }
         $Pos = $Forward ? $LocO->PosEnd + 1 : $LocO->PosBeg - 1;
         unset($LocO);
         $LocO = clsTinyButStrong::f_Xml_FindTag($Txt, $Tag, true, $Pos, $Forward, $LevelStop, $WithPrm, $WithPrm);
         if ($LocO === false) {
             return false;
         }
     }
     $Loc->AttForward = $Forward;
     $Loc->AttTagBeg = $LocO->PosBeg;
     $Loc->AttTagEnd = $LocO->PosEnd;
     $Loc->AttDelimChr = false;
     if (isset($LocO->PrmLst[$Att])) {
         // The attribute is existing
         $p = $LocO->PrmPos[$Att];
         $Loc->AttBeg = $p[0];
         $p[3]--;
         while ($Txt[$p[3]] === ' ') {
             $p[3]--;
         }
         // external end of the attribute, may has an extra spaces
         $Loc->AttEnd = $p[3];
         $Loc->AttDelimCnt = $p[5];
         $Loc->AttDelimChr = $p[4];
         if ($p[1] > $p[0] and $p[2] > $p[1]) {
             //$Loc->AttNameEnd =  $p[1];
             $Loc->AttValBeg = $p[2];
         } else {
             // attribute without value
             //$Loc->AttNameEnd =  $p[3];
             $Loc->AttValBeg = false;
         }
     } else {
         // The attribute is not yet existing
         $Loc->AttDelimCnt = 0;
         $Loc->AttBeg = false;
         $Loc->AttName = $Att;
     }
     // Search for a delimitor
     if ($Loc->AttDelimCnt == 0 and isset($LocO->PrmPos)) {
         foreach ($LocO->PrmPos as $p) {
             if ($p[5] > 0) {
                 $Loc->AttDelimChr = $p[4];
             }
         }
     }
     if ($Move) {
         return clsTinyButStrong::f_Xml_AttMove($Txt, $Loc, $AttDelim);
     }
     return true;
 }