Printing out the alphabet quickly with PHP
Yes, I don’t know when you’d have a practical use for this… but it’s still a neat trick!
<?php for ($i=65; $i<=90; $i++) { $x = chr($i); echo $x; } for ($i=97; $i<=122; $i++) { $x = chr($i); echo $x; } ?>
Personal Blog, Portfolio and Meanderings
Yes, I don’t know when you’d have a practical use for this… but it’s still a neat trick!
<?php for ($i=65; $i<=90; $i++) { $x = chr($i); echo $x; } for ($i=97; $i<=122; $i++) { $x = chr($i); echo $x; } ?>
At my current job, I am a web producer so there’s a lot of formatting articles and then shoving them into a CMS. For the first few weeks of working here, I used to do it manually… one at a time. Then I started using Dreamweaver to do it with the ctrl+shift+p shortcut. One day sitting at home, I created a “tool” to do it for me with some simple regular expressions:
$edit = str_replace("\r\n\r\n","</p><p>",$text);
This was all fine and dandy for me but when you work with a company where some people like to copy and paste from MS Word, curly quotes can be an issue. I had opened my tool to a few coworkers initially and after curly quotes were an often enough problem, I implemented a search and replace for that while p tagging the content:
function convert_smart_quotes($string) { $search = array(chr(145), chr(146), chr(147), chr(148), chr(151)); $replace = array("'", "'", '"', '"', '-'); return str_replace($search, $replace, $string); } $text = convert_smart_quotes(htmlentities($_POST['text']));
Here is the finish product, not fancy or decorated at all since it’s just a tool for convenience.
Today while at work, someone asked me about Wordpress and once I heard the inquiry, I had the “oops” moment.
Person: There’s a problem with the date. Some of the entries don’t display the date on the archive pages.
Stephanie: Oh huh, that’s weird. Is it on the other blogs?
Stephanie’s brain: Dammit, I forgot about how the_date() and the_time() works different.
But I fixed the issue. Basically, when using Wordpress, if you want to display the date on ALL the entries, you should be using the_time() function. However, if you only want it on the first entry of that day (as oppose to having it on ALL the entries), you want to use the_date function.
Simple tip, easy to forget. :]
I’ve been out of tune with PHP, I realize. Can’t be blamed. I have a job that isn’t programming related, and most days, I’m too busy to really look into the new things dealing with PHP. However, currently, I’m rebuilding my portfolio. At first, the idea was, get the static site up and then slowly making it dynamic later. However, while I got the foundation all built, I realized that a lot of the pages I want would be redundant to build. With the time I put into building every page, I could whip out a Portfolio CMS.
Basic functions I’m looking into:
I’m used to procedural programming but this time around, I’m going the object-oriented method which is taking more time because I want to do it right. I must say, after a few tutorials on the concept of OOP, I can see why some would prefer this method. It’s less messy and more organized. I find that I can read my PHP a lot more now than before.
I used to be an avid World of Warcraft gamer. The keyword is used to be. Back in 2008, I built a PHP tool to calculate some gaming stats. Basically it involved a lot of math. In sheer determination to fix up a lot of my personal projects, I went ahead and gave it a minimal simple new layout and cleaner xhtml.
There’s a bit of php math going on in this project (which was how I learned most of the php math I know today):
// formulas $base_regen = 0.005575; $mp5 = 5 * (0.001 + sqrt($int) * $spirit * $base_regen); $mp5_from_gear = $head + $neck + $shoulder + $back + $chest + $bracers + $gloves + $waist + $pants + $boots + $ring1 + $ring2 + $trink1 + $trink2+ $weapon + $offhand + $idol; $spirit_without_ls = $spirit - (floor($spirit * 0.15)); $mp5_without_ls = (0.001 + sqrt($int) * $spirit_without_ls * $base_regen);
One of these days, I’m going to find a better way to do all those calculations. Haha.
Check out the current version here.