Category Archives: PHP

PHP validate email addresses

To rapidly, and decently, validate email addresses, we can use something like this: The filter_var() returns the filtered data or FALSE if it fails Read about it, and more filters, here: – function filter_var()

PHP error reporting – turning on or off

So you wrote this awesome php script, that does extreme stuff, but when you run it…it shows nothing. Empty browser. So whats going on? Well, for one, your php error reporting might be turned off by default. So how to turn it on? Read and learn. And forget tomorrow, like me.

Where is php.ini

If you are configuring some remote strange not safe for work server and you have the urge to edit the php.ini – assuming you have permissions to do it – you can find out where the file is like this: read on.

Preventing SQL injection in PHP/MySQL with PDO

This is a bit old but i wanted to add it here so it stays on record. SQL injection is the action to inject SQL code in web forms to perform a site attack and disrupt its services. For a better definition, go read wikipedia here (it even has some code for you to test… Read More »

AMFPHP 1.9 problem with PHP 5.4

I was developing an application at work that used amfphp 1.9. All was working until i decided to bring it home to work over the weekend (thats already a bad thing to do right there), and i started getting errors. At work i use windows 7+xampp (with php 5.3.8), at home i use windows 8+xampp… Read More »

XAMPP PHP not working with PostgreSQL

This is a recurring problem i had. For some reason (which i later found out), i couldnt get my php scripts to connect to postgresql. The scripts borked at, for example, pg_connect() (unable to find the function, blah blah). First off, usually php doesnt come configured to run the postgresql dll out of the box… Read More »

PHPMaker automatic thumbnail creation

To create a thumbnail to go along with the image you upload to the DB using PHPMaker, you do something like this: For the sake of simplicity, let’s assume you have two directories: – “imgs_sessoes” – for all the regular size images – “imgs_sessoes_tn” – for the thumbnails After configuring PHPMaker to upload, and resize… Read More »

Count words using Regex

Yes, i know, very very easy. But i am leaving this here as reference: $texto = “how to count words in a very simple step”; $contagem = preg_match_all(“/\w+/”, $texto, $blaharray); echo $contagem; // 9 For further reading: Regular Expressions info preg_match() preg_match_all()

include() vs require() vs *_once()

Just to settle this once and for all: include(‘file.php’); // will include file.php and emite a WARNING if the file is not found require(‘file.php’); // will include file.php and emit a FATAL ERROR if the file is not found require_once(‘file.php’); // PHP will check if the file has already been included, and if so, not… Read More »

Install php-gd with yum

Again, as a reminder because this was the second time i had to install php-gd manually on one of my servers: yum install php-gd wash, rinse, restart, play. Note: to restart apache: “apachectl restart” (restarts apache, not worrying about open connections) “apachectl graceful” (restarts apache, but waits for open connections to resolve)