Category Archives: PHP

Find string in string

Like other people i’ve seen complaining about in the net, i keep forgetting how to do this. There are several ways of doing this, but here’s a simple one: $haystack = “Once upon a time, on a far away kingdom…”; $needle = “kingdom”; if(strstr($haystack,$needle)){ echo “Word found.”; }else{ echo “Couldn’t find the word.”; } The… Read More »

Number formatting/padding before and after the decimal

Before i came up with this solution, i had some trouble formatting and padding decimal numbers, specifically when i want to do it before and after the decimal mark. To top it all, i wanted the result signed (with a plus sign(+) or minus sign(-) depending on the value of the variable) Example: I want… Read More »