Monthly Archives: May 2013

PHP Video Training and What to Look For in PHP Training Classes

I’m a visual learner, and like moving at my own pace when digesting new information. Trying to find good PHP video training sessions online can be difficult. I’ve spent hours searching the internet, going on YouTube, and doing Google searches only to come up with a handful of basic lessons, or inferior video demonstrations.

I’ve also ran across guides, or quick references, that just aren’t going to teach me all the fundamentals of PHP programming I need.

Four Components of Effective PHP Training

In all my searching, and watching countless hours of random PHP video training sessions, I’ve come to understand there are really five main areas that need to be covered in any PHP training. They are:

  • Linux: A foundation in Linux will prepare you to use its features and program more effectively.
  • Apache: Writing .htaccess files,  or changing the environment variable? You’ll need to know what you are dealing with.
  • MySQL: Dynamic websites are built around database management systems. In Web2.0, consider MySQL knowledge a must.
  • HTML: Just a solid fundamental to have prior to learning PHP
  • CSS: Allows you to design with style

Many other factors will enhance your site functionality, but the above are the necessities. And there is no better way to learn PHP programming than to follow along with someone as they do it.

Learn at Your Own Pace

I think PHP video training is the best way to learn PHP, without paying $1000’s of dollars to take an in person class. If you can find video training that is supplemented with a text, example scripts, and modules, you’ll be well on your way to learning PHP quickly.

[ad_2]

Source link

The Process of Creating a Website

There are many reasons to build a website. Maybe you want to promote a product, or your business, or just give the general public information about a certain subject. No matter what your reason there are steps you need to take to getting you website online. Most people don’t know you need to buy a domain, get hosting and design a site. It is not as easy as getting a template and plugging it online.

The first and most important step is buying a domain name. Depending on your reason for setting up a website this is a vital step to building a website. If you are hoping to drive in a lot of traffic from search engine results you need to carefully pick a domain. There are some arguments on how search results are conducted but the research shows the domain name can have effect on where your website pulls up on the rankings. Of course other factor weigh in as well, such as, link backs, content, images, keywords, keyword density and meta information. But picking a domain that contains or is the main keyword of your business really helps. For example, if your website is about Widget ABC and your domain is WidgetABC.com you have a better chance of coming up in the search engine than someone selling WidgetABC’s but has a domain of BestPriceForYou.com. Pick your domain name carefully but after you pick your domain you are ready to move onto hosting.

Picking hosting can be pretty tricky as well. Depending on how much traffic you get you may need your own servers. Most people will need basic hosting and can find a good company by doing a Google search for affordable hosting and looking at reviews.

Once you find a host you need to change the namesevers of your domain to reflect that of you hosting. If you bought the domain and hosting from the same company you may not have to worry about changing the name servers they probably have done that for you already.

Now that you have your hosting and domain name chosen you need to begin building. Most host companies will come with a website builder, if they don’t you can always use Frontpage or Dreamweaver. You can find templates online as well. If you can’t find a template you like or want a custom design you can either build it yourself using html, css, flash, php, or other languages but you also have the option of outsourcing it to other web designers. You can also view tutorials online or buy a book from your local book store if you run into a problem.

[ad_2]

Source link

Working With Fractions In PHP

Displaying Fractions In HTML

There are a few ways to display fractions in the web. The most common way is just to add a slash between 2 numbers, like so “1/2”. There are also special HTML characters that we can make fractions look more professional. Eg. to display 1/2, we can use the HTML code &frac12. However, not many fractions are supported by HTML. So, you may be in trouble if you want to display 2/9 in HTML.

A better way to display a fraction is probably to use the superscript and subscript tags. The HTML will be 2/9. We can also use a “special slash” ⁄ between 2 numbers instead of a normal slash ( / ) to make the fraction look better. The fraction will now look like this: 2⁄9. Still not satisfied? With CSS, we can push the limit further.

If we define a css like this:

.fracNum, .fracDen {

font-size: 70%; } .fracNum { vertical-align: 0.5em; } .fracDen { vertical-align: -0.5em; }

and when implemented with the superscript and subscript tags :

2⁄9

fracNum, .fracDen { font-size: 70%; } .fracNum { vertical-align: 0.5em; } .fracDen { vertical-align: -0.5em; } The fraction will now be displayed like this: 3⁄16

* The fractions might not be displayed correctly because of the online editor.

Converting Decimals To Fraction – A Real Example

I wrote a program that let people frame their pictures online. When I was halfway through, I was told that the program should support imperial measurements (inches). The problem with working in inches is that very few people would say my picture is 6.34 inch width by 9.82 inch height; Most people would say 6 and 3/8 inch by 9 and 3/8 height for example.

The biggest problem now is that the framing engine calculates everything in mm. Instead of rewritting the whole engine, I figured out that what I need is just an interface to convert mm to inches. So, if I pass 300mm into a function, it should return me 11 and 3/4 as the answer. Dividing 300mm by 1 inch (25.4mm) will leave me with a long decimal. It would be silly to try and display a fraction for a decimal like 0.1111. The function should be intelligent enough to round off the decimal to something that can be easily displayed as a fraction. For example, if I round off 0.1111 to 0.125, I can display the fraction as 1/8 instead of 1111/100000. Time is running short and I need a simple and sweet solution.

Implementation

I would like to go through snipplets of code with explanation first before revealing everything. Feel free to jump to the end of the page and copy the whole function if you just want to implement it in your website. The code is written in PHP.

Part 1: Extracting the decimal in inches.

define(INCH_TO_MM, 25.4);

// 1 inch equals to 25.4mm

$inch = $mm / INCH_TO_MM;

$pWhole = explode(‘.’,$inch); $pWhole = $pWhole[0];

$pDecimal = $val-$pWhole;

The measurement in mm is first converted to inches(with decimal). The decimal is then isolated from the whole number and stored in a var call $pDecimal. Now, I need to store a list of all possible fractions with their mm equivalent in an array. I use intervals of 1/8 for the sake of simplicity.

Part 2: Rounding off to the closest inch interval.

$fractionOption = array();

$fractionOption[‘0/8’] = 0;

$fractionOption[‘1/8’] = 0.125;

$fractionOption[‘1/4’] = 0.25;

$fractionOption[‘3/8’] = 0.375;

$fractionOption[‘1/2’] = 0.5;

$fractionOption[‘5/8’] = 0.625;

$fractionOption[‘3/4’] = 0.75;

$fractionOption[‘7/8’] = 0.875;

$fractionOption[‘8/8’] = 1;

foreach ($fractionOption as $k => $v) {

// Converted $pDecimal back to mm to perform calculation

$tmpV[$k] = abs($pDecimal – $v);

}

asort($tmpV,SORT_NUMERIC);

list($inch, $mm) = each($tmpV);

This is the most important step in the whole conversion process. The foreach loop creates a new array called $tmpV which stores the inch fraction as the key and the inch difference as the value. We will now sort $tmpV with the minimum ‘mm’ value at the top and the maximum ‘mm’ value at the bottom using the ‘asort’ function. We are extracting the first entry in the array because it stores the minimum ‘mm’ difference. As you can see, what we are trying to do here is to round $pDecimal off to the closest decimal value in the $fractionOption array (ie, 0.125, 0.25, 0.375..etc).

I can now safely extract the first key-value pair in $tmpV using the ‘list’ function. The $inch var stores the inch representation that we want.

Part 3: Cleaning Up

$inch = ($inch == ‘0/8’) ? ”: $inch; // round off to nearest whole number if 8/8 if ($inch == ‘8/8’) { $inch = ”;

$pWhole++; }

We do not want to display the fraction if it is ‘0/8’ or ‘8/8’ because it is pretty much meaningless. However, if the fraction is ‘8/8’, we have to increase the whole number by 1.

Part 4: Adding some CSS

if ($inch != ”) {

$tFrac = explode(‘/’,$inch);

$fraction = “$tFrac[0]⁄$tFrac[1]”; } else {

$fraction = ”; } return “$pWhole $fraction”;

Remember that we eliminated any fractions that are ‘0/8’ or ‘8/8’? So we only need to process any fraction that falls within the range of ‘1/8’ to ‘7/8’. By splitting the fractions into numerators and denominators, we can now apply our CSS technique mentioned above.

The Whole Thing

As promised, the full code is displayed below:

function mmToInch ($val) {

$fractionOption = array();

$fractionOption[‘0/8’] = 0;

$fractionOption[‘1/8’] = 0.125;

$fractionOption[‘1/4’] = 0.25;

$fractionOption[‘3/8’] = 0.375;

$fractionOption[‘1/2’] = 0.5;

$fractionOption[‘5/8’] = 0.625;

$fractionOption[‘3/4’] = 0.75;

$fractionOption[‘7/8’] = 0.875;

$fractionOption[‘8/8’] = 1;

define(INCH_TO_MM, 25.4);

$val = $val/INCH_TO_MM;

$pWhole = explode(‘.’,$val);

$pWhole = $pWhole[0];

$pDecimal = $val-$pWhole;

foreach ($fractionOption as $k => $v) {

$tmpV[$k] = abs($pDecimal – $v);

}

asort($tmpV,SORT_NUMERIC);

list($inch, $mm) = each($tmpV);

// nullify pWhole and pFraction

$pWhole = ($pWhole == 0) ? ”: $pWhole;

$inch = ($inch == ‘0/8’) ? ”: $inch;

// round off to nearest whole number if 8/8

if ($inch == ‘8/8’) {

$inch = ”;

$pWhole++;

}

// strip inch and return fraction formatted in css

if ($inch != ”) {

$tFrac = explode(‘/’,$inch);

$fraction = “$tFrac[0]⁄$tFrac[1]”;

}

else {

$fraction = ”;

}

return $pWhole.’ ‘.$fraction; }

// testing echo “67.885 mm is equivalent to “.mmToInch(66.885).” inches”;

?>

The sourcecode can be dowloaded here

Conclusion

I hope that the decimal to fraction conversion solution shown in this tutorial is straight forward and easy to implement. The script rounds off any decimal value to the closest one-eighth of an inch. If you want more accuracy, you can make your fraction interval smaller, for example 1/16 or 1/32…and so on. The logic used in this example can be easily applied to other programming languages. Feel free to try the online framing program at www.clubframeco.com/smartFramer.html. Make sure you select the inch option to see fractions in action.

[ad_2]

Source link