Sunday, January 04, 2009

Websites for Parents of Gifted Children

  1. ERIC Clearinghouse on Gifted Children
  2. An excellent resource for parents offering hundreds of digests on a wide variety of topics related to gifted children.

  3. Gifted Children Monthly
  4. A newsletter for parents of gifted children.

  5. GT World
  6. An online support network for parents of gifted and talented children.

  7. Hoagies Gifted Education Page
  8. An extensive online resource for parents and teachers on a range of subjects related to giftedness.

  9. National Association for Gifted Children
  10. NAGC advocates in Congress and at the U.S. Department of Education on behalf of the gifted education community to increase federal support for gifted and talented learners. A wealth of information on giftedness is available on this page.

Credits: Philippine Daily Inquirer

Tuesday, December 16, 2008

10 Most Common Money Mistakes

WHAT money mistakes can turn P20,000 to waste in a year?

While mistakes are normal (even so-called experts make them), it won't hurt to know which ones you are committing and how to learn from them.

Putting your act together financially may prove especially useful when times are tough and rocky because even little mistakes that happen again and again can set you back thousands of pesos in a year.

Here are 10 money mistakes most of us make:

Mistake #1: Living beyond your means

Filipinos are consumed with "wanting to live a better life."

Are you trying to live "that kind of life" with income that cannot sustain that lifestyle and ending up spending more than your monthly paycheck? Yes, you can fund that lifestyle with debt. Don't. Spending more than you earn is the surest way to keep that "better life" further away from reach.

Ralph Liew, chairman of the International Association of Regional Financial Consultants (IARFC) for the Philippines, Thailand, Malaysia and India, points out that the millionaires next door are the ones who save so much more than they spend.

"They are the ones who are saving a lot of money," he says.

The fix: Put off expenses if the income for the month will put you in debt or cause you not to save money for that period. Thinking twice about small things like the cost of lunch, a frapuccino or dinner at a restaurant will instill discipline and the habit of living within your means, which is most valuable in fixing money mistakes.

Mistake #2: Not saving enough

You've heard of the expression "It's not what you make that matters, it's what you keep." Saving monthly is the fundamental habit that makes any person-- whether a Jollibee crew or a professional working in a posh office in Makati--wealthy. Starting your first job and earning minimum wage may not make it easy for you to save regularly, but P50 savings per week in a simple jar near your bed is not a bad start.

As you mature, it will be easier to set aside a bigger chunk of money because you've been used to the habit.

"I save half of my salary automatically and try not to think about it," says Anna, a professional working in Ortigas.

The fix: Find a way to automate your savings to make it easier for you to save. There are some banks that provide this service. Make it a goal to save monthly, even if it's just a small part of your income--say 10 percent. Then increase this regularly when finances allow you to squirrel away more of your income.

Mistake #3: Being materialistic

It is common to see families in the provinces living simply with chickens running around in the yard, pigs being raised in the backyard, malunggay and other vegetables growing near the home. IARFC's Liew says when he saw Filipinos living this way, he realized that living simply and not measuring your worth by looking at what you have and what you can buy makes a person's life more meaningful.

"Don't try to keep up with the Joneses and don't just keep looking at the material part of life. Be frugal; don't overspend. Some of the people I see in the provinces live simply and they are okay," says Liew.

The fix: Keep your attention focused on the things that matter most: health, family, friends, and community. While money may make your children happy because of the things that it buys, there are other things that will make them equally happy, like loving attention, quality time and playing together, among others. Sometimes, the returns from non-monetary gifts are even higher.

Mistake #4: Giving in to greed

Billions of pesos every year are sucked into get-rich-quick schemes and scams that easily separates a Filipino from his hard-earned money. Liew says the reason for this is greed. Running after very high returns is a sure way of getting scammed.

The fix: Don't be wowed by quick wealth. Lightning may strike for some people, but the more stable and sure way to wealth is a slow accumulation of savings and investments. How about that hot stock tip or "new investment strategy" earning four percent in a day that made someone a millionaire? Just walk away from it. They will never tell you just how quickly they lost their money.

Mistake #5: Not knowing what you want

"People don't know what they want and then they end up wanting everything they see," says Liew. One of the building blocks of wealth is to know yourself and your limitations as well as your strengths. Husbands, wives and children should take time to talk about financial goals (i.e. our own home in three years, our own car in two years, studies in the United States for Junior in 10 years, etc.).

The fix: New Year or this coming Christmas holiday is a good time to create a financial road map for yourself or your family. Talk about what you want and how you intend to get there. Think about how long you want to attain your goals. Make a pact to revisit your goals every year to see how you are doing.

Mistake #6: Failing to pay off debts

The Philippines owes P122 billion in credit card debt, P14.2 billion of which have already fallen overdue as of June. Unfortunately, that's only a small part of consumer debt, as loan sharks still abound. Debt is like a Damocles sword that hangs over your head and makes you afraid to wake up in the morning.

Interest from debt never sleeps; it doesn't take days off or holidays. They are worms that eat voraciously at your financial dreams.

The fix: If you are thinking of borrowing money with no plan on how to repay it, don't.

If you have debt or several debts that need to be paid, create a plan now.

Start paying the ones with the highest interest while paying off the others with as much money as you can spare.

Then work on through that list until you have paid everything.

Mistake #7: Getting killed by advertisements

Glossy magazine inserts come in through the mail at a frenzied pace when the holiday season draws near. There are flat-screen LCD televisions to buy and new mobile phone models. Resist them if you don't need them or can't afford them yet.

The fix: If you are vulnerable to advertisements, make the remote your best friend and speed up your channel surfing. Don't even start flipping that glossy magazine insert. Avoiding advertisements or keeping yourself disciplined enough to enjoy them from a distance should help you keep your finances secure this holiday season.

Mistake #8: Not having a plan

"One of our most common mistakes is not having a financial plan, not following up on the plan and not implementing the plan," says Liew. He notes that many people have New Year's resolutions--for example, to quit smoking--but find themselves still doing so when the next New Year's eve arrives.

The fix: Give yourself the gift of your very own financial plan this Christmas season. You can talk to a financial planner to help you out or do it yourself.

There are many resources on the Internet to help you create a plan that will save you from money mistakes and point you to the right direction when it comes to understanding your money personality, how to save and invest, how to prepare to retire wealthy and prepare to be pampered in your golden years.

One of these is MoneySmarts, the personal finance blog of the INQUIRER.net.

Mistake #9: Not having financial education

People think financial education is only for those working in banks, mutual funds or in the financial services industry.

Granted, mathematics or statistics are not easy subjects for all, but knowing financial principles is useful to everyone.

Liew says that even children should have subjects on financial management.

The fix: Don't be shy. Ask among your friends if they know something about taking care of finances. Invest in books and take classes. Personal finance is a growing topic in local media.

Mistake #10: Procrastinating

Time doesn't stand still, not even for the Pope.

The best time to start making money moves that will save you from a life of want and need is now, not tomorrow or next week.

The best time to start a budget is now. The best time to save for retirement is now.

The fix: Stop reading and start doing.


Credits: Philippine Daily Inquirer

Friday, October 03, 2008

Get Started With SimpleXML in PHP

If you're starting out in web development, you're probably going to have to transfer data between applications. These days, most do this using XML. XML is a protocol used to share data, especially via public APIs.

Hacking XML code can get pretty messy and unmanageable if you don't know what you're doing. Mercifully, PHP 5 has a library called SimpleXML that lives up to its name. The hard work of turning XML into a usable format for programming is done for you. All that's left is working with the object SimpleXML creates.

In this tutorial, I'll show you how to make sense of the SimpleXMLElement object and the many ways it can be used. Come to the head of the class, because it's time for SimpleXML School.

What you'll need
  • PHP 5, a programming language available on many web hosts.
  • SimpleXML, a library usually installed along with PHP 5.
  • Some knowledge of PHP and XML

Example XML File

You can download the example XML we'll use in this section, or copy the text below into your own file named school.xml. Make sure you store this file in the same directory as your PHP file.
<?xml version="1.0"?>
<school>
<grades>
<grade>
<level>K</level>
<student_count>
<boys>49</boys>
<girls>41</girls>
</student_count>
</grade>
<grade>
<level>1</level>
<student_count>
<boys>29</boys>
<girls>32</girls>
</student_count>
</grade>
<grade>
<level>2</level>
<student_count>
<boys>26</boys>
<girls>31</girls>
</student_count>
</grade>
</grades>
<principal>
<name>Dr. Hamilton</name>
<experience timein="years">
<time>14</time>
</experience>
</principal>
<classrooms />
</school>

Read in XML

The most common way to use XML in your PHP programs is "reading in" someone else's XML. Most APIs output their data as XML. To be able to use these APIs, you need to be able to read in, parse, and make sense of the XML it sends.

Read XML From a File

To read the XML from school.xml, use the simplexml_load_file function:
$xmlobj = simplexml_load_file("school.xml");
print header("Content-type: text/plain");
print_r($xmlobj);

I have also printed out the way the XML is interpretted in PHP: as a SimpleXMLElement object.

SimpleXMLElement Object
(
[grades] => SimpleXMLElement Object
(
[grade] => Array
(
[0] => SimpleXMLElement Object
(
[level] => K
[student_count] => SimpleXMLElement Object
(
[boys] => 49
[girls] => 41
)
)

[1] => SimpleXMLElement Object
(
[level] => 1
[student_count] => SimpleXMLElement Object
(
[boys] => 29
[girls] => 32
)
)

[2] => SimpleXMLElement Object
(
[level] => 2
[student_count] => SimpleXMLElement Object
(
[boys] => 26
[girls] => 31
)
)
)
)

[principal] => SimpleXMLElement Object
(
[name] => Dr. Hamilton
[experience] => SimpleXMLElement Object
(
[@attributes] => Array
(
[timein] => years
)

[time] => 14
)
)
)

Read XML From a String

To create a SimpleXMLElement object from a string of text, use the simplexml_load_string function:
$xmltext = join(file("school.xml"), "");
$xmlobj = simplexml_load_string($xmltext);
print header("Content-type: text/plain");
print_r($xmlobj);

Here I loaded the school.xml text into a string variable ($xmltext), before passing it to the simplexml_load_string function. If this looks like an extra step, it is in this case. But if you received a string from an API, you'd want to be able to use this function.

Now that we have a SimpleXMLElement object, let's talk about how to use it.

Understand the SimpleXMLElement Object

The SimpleXMLElement object is how SimpleXML converts textual XML into a format that PHP can understand. The object is essentially a collection of tag names with the values inside the tag. As is common in XML, sometimes a tag contains other tags. In that case, the value of a tag is actually another SimpleXMLElement object.

Take a look at the strange indented text that my code above has produced. It begins with a SimpleXMLElement object. The next thing is the <grades> tag, which is itself another SimpleXMLElement object. It contains a <grade> tag, which has an array of—you guessed it—SimpleXMLElement objects.

There's not much use to printing out the entire object, other than to understand it. So, now let's try accessing some individual pieces of data.

Want to print out the name of the principal? Try this:
print $xmlobj->principal->name;

Which produces the name of the principal from the XML file:
Dr. Hamilton

How about the number of boys in Kindergarten? That gets a little more complicated:
print $xmlobj->grades->grade[0]->student_count->boys;

As expected, it outputs the number of boys from the "zeroth" grade element:
49

Luckily, SimpleXML has another even easier way to access pieces of the results. It's called XPath, and you can find out more in the next section.

Use XPath for Even Simpler XML Access

XPath is a web standard, just like XML. XPath is a way to query XML for particular elements and there's a function within SimpleXML that makes XPath a cinch.

All you need to do is call the xpath function on the SimpleXMLElement object with the special "path" you want to find. For example, to get the principal tag and its children, just use this code:
print_r($xmlobj->xpath("/school/principal"));

Notice this example describes the entire path to the <principal>tag, including the root (<school>). Each level is preceded by a slash, including the first one.

Output:
Array
(
[0] => SimpleXMLElement Object
(
[name] => Dr. Hamilton
[experience] => SimpleXMLElement Object
(
[@attributes] => Array
(
[timein] => years
)

[time] => 14
)
)
)

You can also search for all instances of a specific tag, regardless of its place in the hierarchy. The same example above is now shorter:
print_r($xmlobj->xpath("//principal"));

Notice the double-slash at the beginning of the XPath call this time? It tells XPath to look for any <principal> tag. The output is the same as the previous example.

The same double-slash syntax can be used to find multiple results. Here, we'll retrieve an array of all the grade levels in the school:

Output:
Array
(
[0] => SimpleXMLElement Object
(
[0] => K
)

[1] => SimpleXMLElement Object
(
[0] => 1
)

[2] => SimpleXMLElement Object
(
[0] => 2
)
)

You can even call up certain tags based on their content. Here we'll grab any tag that contains a <level> tag with a K (for Kindergarten). Notice the asterisk, which tells XPath to match any tag:
print_r($xmlobj->xpath("//*[level='K']"));

Output:
Array
(
[0] => SimpleXMLElement Object
(
[level] => K
[student_count] => SimpleXMLElement Object
(
[boys] => 49
[girls] => 41
)
)
)

In addition to checking for a specific value, XPath can also look for numbers that are greater than or less than. Here, we get all <student_count> tags with more than 31 girls:
print_r($xmlobj->xpath("//student_count[girls>31]"));

Output:
Array
(
[0] => SimpleXMLElement Object
(
[boys] => 49
[girls] => 41
)

[1] => SimpleXMLElement Object
(
[boys] => 29
[girls] => 32
)
)

Here, it also grabs the <boys> tags, both of which are less than 31. That is because we're only checking against the <girls> tag, but then grabbing its parent, which is also the parent of the boys.

We can include the boys in the count to check the overall count by using XPath's addition operator:
print_r($xmlobj->xpath("//student_count[boys+girls>60]"));

Output:
Array
(
[0] => SimpleXMLElement Object
(
[boys] => 49
[girls] => 41
)

[1] => SimpleXMLElement Object
(
[boys] => 29
[girls] => 32
)
)

Again, both boys and girls are returned, but here they only return if the total of the two counts is above 60.

These many examples are just a small sampling of what XPath can do. Hopefully it helps you find out how to read in and query XML for the data you need. In the next section, we'll look at writing your own XML using SimpleXML.

Write out XML

As you've seen in the previous section, the SimpleXMLElement object is central to using SimpleXML. This object holds the structure of the XML in a way that makes it easy for PHP to access it. However, sometimes we want to output it back as raw XML. For example, if you're creating an API, you would probably be sending XML out as output.

Output SimpleXMLElement Object as XML

If you already have a SimpleXMLElement object, writing out the XML is as easy as calling the correct function: asXML.

Assuming you have a SimpleXMLElement object called $xmlobj, here's the code you need to print out as XML:
print $xmlobj->asXML();

The print command does the printing, because asXML just returns the content. If you don't want to immediately output the XML, you can store the content into a variable:
$xmltext = $xmlobj->asXML();

Now that you know how to print out the XML, let's create a SimpleXMLElement object from scratch.

Create SimpleXMLElement from Scratch

When you want to create XML, using the SimpleXMLElement object can help avoid errors in syntax, so you know your XML is as good as your object.

Before we create a SimpleXMLElement from scratch programatically, let's look at the XML we want to achieve:
<?xml version="1.0"?>
<classroom>
<teacher>Mr. Deckelmann</teacher>
<students>
<student>Sammy</student>
<student gender="F">Daisy</student>
</students>
</classroom>

Start with XML and Root Tag

To create an empty SimpleXMLElement object, you can pass an XML structure essentially void of content. Here we'll give it just an <xml> tag, then create a root tag. In this case, I've chosen <classroom> as my root element, under which I'll add all other XML tags.

Here's the code to give us an empty SimpleXMLElement:
$xmltext = "\n<classroom></classroom>";
$xmlobj = simplexml_load_string($xmltext);

The first line holds the blank XML. The second line uses that XML to create a SimpleXMLElement object.

Add Elements to SimpleXMLElement

The SimpleXMLElement object doesn't do us much good unless we start adding elements to it. Glancing up at the XML we're hoping to achieve, I see we need a <teacher> tag next. To add this, we need to call the addChild function on our SimpleXMLElement object. This function takes two arguments: the name of the tag and the value. Here's the code:
$xmlobj->addChild("teacher", "Mr. Deckelmann");

print header("Content-type: text/plain") . $xmlobj->asXML();

The $xmlobj variable from the previous section holds the empty SimpleXMLElement. To call a function on an object, we use the -> operator, followed by the name of the function.

The asXML line might look familiar from the above. It prints out the XML code from the SimpleXMLElement object. In future sections, you'll need to put new code above that line to avoid printing before all your XML is in place.

Save your PHP file and load it up in your browser. You should now see our XML. Blown away? Probably not, but let's add some more elements and see if we can change that.

Add Sub-Elements to SimpleXMLElement

Now that we've added a normal element, let's get more advanced and create an element that contains other elements. To do this, we need to create a new element, then get access to the new object.

Luckily, the addChild function we used above returns the new object that it creates. Here is the code to create a sub-element:
$studentsobj = $xmlobj->addChild("students");
$studentsobj->addChild("student", "Sammy");

(Remember to place the code above the asXML line).

The first line creates an empty <students> tag. In addition to creating the tag, it also sends the output of the addChild function to the $studentsobj variable. The output is a new SimpleXMLElement object holding just the new tag.

Calling the addChild function on the new object, as we did in the second line, creates a <student> tag. This second line is similar to the <teacher> tag we added, but here is will go inside the <students> tag instead of under the root tag.

Reload the file and see for yourself. We're now most of the way toward re-creating some XML by using SimpleXML. Just one tiny step remaining.

Add Attributes to SimpleXMLElements

Attributes go inside XML tags. They often hold meta-data, which supports the main data, but is not as important. Sometimes the value is extremely important, such as the anchor tag in HTML, which stores the URL inside the href attribute.

Here are are going to add a new student named Daisy and set a gender attribute of "F" for her. Here's the code:
$daisyobj = $studentsobj->addChild("student", "Daisy");
$daisyobj->addAttribute("gender", "F");

(Remember to place that code above the asXML line).

The first line may look familiar. As with adding the first child (Sammy) above, we need to call the addChild function on the $studentsobj variable. The difference is that we set the output of that call to yet another SimpleXMLElement object. This one holds only the data for the most recent tag, Daisy's <student> tag.

We use the newest object to add an attribute for Daisy. The name of the attribute is "gender" and the value is "F." So, when you reload the PHP file again, you should now see the complete XML that we were trying to emulate.

I hope you're at least a little bit blown away now, because you just created an entire XML file programmatically.

Where to Use SimpleXML

Now that you know how to read and write XML with SimpleXML, you're probably looking for ways to use it. As I've mentioned above, APIs often output XML, so that's a good place to start. Below we have some tutorials that use SimpleXML to parse real live XML from APIs.


Credits: Webmonkey