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.

Visual Studio Custom Skins (Without Paying)

Filed Under (Code, Learn C#) by Mystalia on 27-03-2009

Tagged Under : , , , , , , , ,

It’s a nightmare to get custom skins without paying an arm and a leg for such a simple part of your program. Some companys ask for hundreds of dollars for simple .NET classes, it’s crazy, anyway, here’s a workaround that is 100% legal and 100% free.

This screenshot is VERY easy to achieve, no fancy software just 1 class, one dll, one msstyle and a few lines of code.

Below are the class file and dll, and i’ve thrown in a couple of msstyles to get you going, theres plenty more on the internet, theres a few on SkinBase.org. We are using USkin (Homepage) its the classes that do all the work, the documentation and examples are terrible but after trial and error I have figured it out and will explain in this article.

Download Uskin easy pack here

Right click the solution explorer, add an existing item (”USkinSDK.cs” and “USkin.dll”).
Make sure the dll properties are set to “Content” and “Copy Always”.
Make sure the class properties are set to “Compile” and “Never Copy”.

The code is simple.

using USkin; // declare it.
 
        private void Form1_Load(object sender, EventArgs e)
        {
            Size presize = this.Size; // Get the correct form size before the GUI mucks it up.
            USkinSDK.USkinInit("", "", "GUI.msstyles"); // Replace the text accordingly with your msstyles file.
            USkinSDK.USkinLoadSkin("GUI.msstyles"); // And again here.
            this.Size = presize; // Re-establish the form size.
        }

Simple and effective to make your applications look more professional. I will note however that you should get prior permission from the skin creator before using your application commercially, or just create your own, that’s easy too.

Hope this helps!

Basic C#.NET Syntax

Filed Under (Learn C#) by Mystalia on 15-03-2009

Start a new windows form application like in the previous tutorial.

Drag a new button in the middle and set the text to “Off”.
Now over in the Solution explorer, right click “Form1.cs” and click View Code.

You will see a bunch of Statements, and these are lines of code. Each statement as you can see, finish with a semi-colon (;).
The code is organised into .NET Libraries, namespaces, classes and methods or functions.

The using statements at the top are .net libraries that are included, for this tutorial we won’t need any more then this, but later on we can go into special libraries to include.

A namespace is a collection of classes.
A class is a collection of methods and functions.
A method or function simply completes a task.

The advantage of being a visual studio is that we don’t have to program any user interface, we can just paint it on. At the top there are tabs (Form1.cs, start page, Form1.cs [Design]). Click the Design tab to return to the design view for this application.

Double click the button you made earlier and notice it automatically creates a new function for this button.

private means that the code can only be accessed in the current class.
void means the code will not return anything but only complete a task.
button1_Click is just a name given to associate the button to that task.

Inside the brackets below ({ and }) we will perform a task when the user clicks the button. Type “button1” and then press put a full stop, notice a window appears giving you suggested options for the button. Type “Text” (case sensative) and then press Space. We will now set the button text to something else by pressing the Equals button and then in quote marks type “Goodbye” and finish the statement with a semi-colon.

button1.Text = "Goodbye";

Now click the test button and then your new button and see what happens!

In the next tutorial we will see how statements can contain other statements.

Visual C#.NET – Setting Yourself Up!

Filed Under (Learn C#) by Mystalia on 15-03-2009

This is a tutorial for those who know a little about the concepts of programming and want to design windows applications in C#.

In this tutorial we will:

  1. Learn about what the .NET framework is and why C# is worth the effort.
  2. Download and Setup the software needed to make C# applications.
  3. Get used to the Interface.

.NET Framework
The .NET Framework is needed to run any C#.NET application, fortunately anyone with vista should already have it installed. Some xp systems don’t have it and it can be downloaded and installed here. It is basically a library of code that exists so you don’t have to manually write it all yourself.

C#.NET
C#.net is comparable to PHP in style, if you know PHP then you will get on well with C#. If you want to program games, C# is a really easy way to go about it because of microsofts XNA Framework, which is a library full of game related code. C# is great to learn and you can get results quickly without too much effort.

Visual Studio 2008 Express Edition
This version of visual studio is absolutely free and downloadable from here. There are different types, so make sure you get Visual C#.NET 2008. You will also obviously need the .NET Framework installed if you don’t have it already.

The Interface
When you start up Visual C# 2008 express you will be greeted with the start page from which you can start a new project or continue one that you already have on the go. If it is your first time, go to File -> New Project. Select Windows Forms Application and name it Test, then click OK.

After it has loaded up, you will see a blank windows form and a bunch of tools down the left hand side. Over on the right you have the solution explorer and the properties menu. At the bottom there should be an error list (for debugging). Don’t worry about any of this right now, they will be covered later on.

Click the Button control in the Toolbox and click and drag a button on the windows form. Notice the Properties menu is now full of options. Change the Text option to “Hello” and then press Enter. Notice the text on the button has changed!

At the top there is a Green Triangle on its side, like a play button. Click this and test the application. Pretty easy right? Play with other controls and options and read the tooltips that appear when you hover your mouse over options and tools etc.

The next tutorial will cover some basic C# Syntax.

Floating Image or HTML over an iframe using CSS.

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

Tagged Under : , , , ,

You can see on http://fileblip.com/4fb26ed7! after clicking the continue button they have a floating
panel over the top of an iFrame.
Take a look at the code here they use, the trick is simply to use position: absolute and
then toy with the left and top values until it is positioned correctly. You must also make
sure the object is floating left or right, but you may have issues on the right.

4b982b160c7a51_

Useful PHP class for parsing HTML

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

Tagged Under : , , , , , , ,

I’m hoping this is commented well enough.

01
class HTMLParse
02
{
03
  // Missing InnerHTML function!
04
  function innerHTML($node){
05
    $doc = new DOMDocument();
06
    foreach ($node->childNodes as $child)
07
      $doc->appendChild($doc->importNode($child, true));
08
 
09
    return $doc->saveHTML();
10
  }
11
 
12
  // Get the inner html of all elements inside tag from the source (input).
13
  function GetInnerArray($tag, $input)
14
  {
15
    $doc = new DOMDocument();
16
    @$doc->loadHTML($input);
17
    $dataset = $doc->getElementsByTagName($tag);
18
 
19
    $stringarr = array();
20
    foreach( $dataset as $row )
21
    {
22
      array_push($stringarr, trim($this->innerHTML($row)));
23
    }
24
    return $stringarr;
25
  }
26
 
27
  // Get the inner html of all elements inside tag where an attribute exists with the value.
28
  function GetInnerArrayFilter($input, $tag, $attribute, $value)
29
  {
30
    $doc = new DOMDocument();
31
    @$doc->loadHTML($input);
32
    $dataset = $doc->getElementsByTagName($tag);
33
 
34
    $stringarr = array();
35
    foreach( $dataset as $row )
36
    {
37
      if($row->getAttribute($attribute) == $value)
38
      {
39
        array_push($stringarr, trim($this->innerHTML($row)));
40
      }
41
    }
42
    return $stringarr;
43
  }
44
 
45
  // Get attribute of tags.
46
  function GetTagAttribute($input, $tag, $attribute)
47
  {
48
    $doc = new DOMDocument();
49
    @$doc->loadHTML($input);
50
    $dataset = $doc->getElementsByTagName($tag);
51
 
52
    $stringarr = array();
53
    foreach( $dataset as $row )
54
    {
55
        array_push($stringarr, $row->getAttribute($attribute));
56
    }
57
    return $stringarr;
58
  }
59
 
60
  // Get attribute of tags where the tag attrib has the value.
61
  function GetTagAttributeFilter($input, $tag, $attribute, $qattrib, $value)
62
  {
63
    $doc = new DOMDocument();
64
    @$doc->loadHTML($input);
65
    $dataset = $doc->getElementsByTagName($tag);
66
 
67
    $stringarr = array();
68
    foreach( $dataset as $row )
69
    {
70
      if($row->getAttribute($qattrib) == $value)
71
      {
72
        array_push($stringarr, $row->getAttribute($attribute));
73
      }
74
    }
75
    return $stringarr;
76
  }
77
}
78
?> 

If you would like help with this class, please comment!
If you have an idea to improve this class, please comment!

C# Draggable Borderless Forms. Solved!

Filed Under (Code) by Mystalia on 17-10-2008

Ever wonder why a windows form without any FormBorders is not able to be dragged around by the mouse? You’d have thought common sense would dictate that a developer would wan’t his app to be fully functional frames or not, but I guess programming on and for windows means that you have to deal with little annoyances like this with a workaround.

Whack this at the top of the class.

// Form moving
#region
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HTCAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
#endregion
// Create a new Form1.MouseDown Event in the form designer and put this into it.
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}

This is presuming you want the form background to be the dragging object, but it can be anything really.

C# Textbox and AutoCompleteMode Conflicts with KeyPress.

Filed Under (Code) by Mystalia on 11-07-2008

Tagged Under : , , , , ,

Ok, personally I was using a textbox and when you pressed “Enter” it would complete a task, BUT I also wanted the textbox to be autocompletive (if that’s a valid term).

When I actually went to test it all out I found that instead of running the Keypress event, it just highlighted the text and did nothing else… Googled to find there is no valid reason why, but there is a work around, and it’s simple.

Abandon KeyPress and use the KeyDown function, setup your keydown event correctly, and it will work.

    private void textBox1_KeyDown(object sender, KeyEventArgs e)
    {
    if (e.KeyCode == Keys.Enter)
    }

Opening a WebPage in the Default Browser (C# .net)

Filed Under (Code) by Mystalia on 28-06-2008

Tagged Under : , , , ,

When you just want to open a webpage in the systems default browser there are many complicated methods to do it, like going through the registry and finding out what the default browser is… blah blah…

SO! Why not just hand the task over to windows…

    using System.Diagnostics;
 
    // In one line of code look...
    Process.Start("http://www.google.com");

And there you go, windows will handle the url as if you had just clicked a shortcut on the desktop and open it with the default browser.

Easy.