Useful HTMLParse Class for PHP

Filed Under (Code) by Mystalia on 11-04-2009

Tagged Under : , , , , , , ,

class HTMLParse
{
  // the missing InnerHTML function!
  function innerHTML($node){
    $doc = new DOMDocument();
    foreach ($node->childNodes as $child)
    {
      $doc->appendChild($doc->importNode($child, true));
    }
    $result = $doc->saveHTML();
    return $result;
  }
  // Get the inner html of all elements inside tag from the source (input).
  function GetInnerArray($tag, $input)
  {
    $doc = new DOMDocument();
    @$doc->loadHTML($input);
    $dataset = $doc->getElementsByTagName($tag);
    $stringarr = array();
    foreach( $dataset as $row )
    {
      array_push($stringarr, trim($this->innerHTML($row)));
    }
    return $stringarr;
  }
  // Get the inner html of all elements inside tag where an attribute exists with the value.
  function GetInnerArrayFilter($input, $tag, $attribute, $value)
  {
    $doc = new DOMDocument();
    @$doc->loadHTML($input);
    $dataset = $doc->getElementsByTagName($tag);
    $stringarr = array();
    foreach( $dataset as $row )
    {
      if($row->getAttribute($attribute) == $value)
      {
        array_push($stringarr, trim($this->innerHTML($row)));
      }
    }
    return $stringarr;
  }
  // Get attribute of tags.
  function GetTagAttribute($input, $tag, $attribute)
  {
    $doc = new DOMDocument();
    @$doc->loadHTML($input);
    $dataset = $doc->getElementsByTagName($tag);
    $stringarr = array();
    foreach( $dataset as $row )
    {
        array_push($stringarr, $row->getAttribute($attribute));
    }
    return $stringarr;
  }
  // Get attribute of tags where the tag attrib has the value.
  function GetTagAttributeFilter($input, $tag, $attribute, $qattrib, $value)
  {
    $doc = new DOMDocument();
    @$doc->loadHTML($input);
    $dataset = $doc->getElementsByTagName($tag);
    $stringarr = array();
    foreach( $dataset as $row )
    {
      if($row->getAttribute($qattrib) == $value)
      {
        array_push($stringarr, $row->getAttribute($attribute));
      }
    }
    return $stringarr;
  }
}
?>

Mostly written by me.

How to restore the Show Desktop Icon to QuickLaunch.

Filed Under (Code) by Mystalia on 04-04-2009

Tagged Under : , , , , , , ,

Run This Batch File and it will automatically place the icon in the QuickLaunch bar, remember if you don’t see it even after running the tool, it’s likely you need to click the double arrows on the right of the bar as it can only show 3. Just drag and drop it onto the 3 there.