PHP Wordpress

Worpress: useful codex commands

<?php get_cat_name( $cat_id ) ?> Get the category name if you have the id of it

<?php get_category_link( $category_id ); ?> Get the category permalink

PHP Wordpress

WordPress: produce new templates that can be used for new pages

Put them on your Themes directory, any php file that is there and includes the following header will be included in the drop-down menu for templates to choose from while creating a page:

<?php/*Template Name: Custom Feed*/

JavaScript PHP Wordpress

WordPress: Adding the version of jquery that comes with the installation


Where is my php.ini?

So you setup a page with phpinfo() on it, and the php.ini path indicated by it does not actually contain a php.ini file? Kind of a weird bug I run across. After searching for all my php.ini files in my linux box (find / -name php.ini) and not being able to find the appropiate one (I keep making changes on them and not see the changes take place after the server restarts) I decided to move my php.ini-dist again to the location specified on the php.ini path of the phpinfo() page. Success !! It fixed the problem. Speculating on this, the problem may have been originated by running the ./configuration option with the prefix and a new path optio


Setting the user agent on a php based bot

The source says it all:


Files not being uploaded on a PHP server

The solution may be something really simple you overlooked: make sure your form contains the enctype=”multipart/form-data” part.

mysql PHP

Extension not found error when trying to run the DB package for php Pear

This only means you did not configure that specific database to be compiled with php. For example, if you get that error when trying to connect to a mysql database, make sure that when you run ./configure (when installing php) you included the -with–mysql option.


Example on how to use php smarty foreach control structure

<p><!–StartFragment –>                       {foreach from=$advertiser_categories item=category}<br />


<li><input id=”category_id_{$category}” type=”checkbox” name=”category_id[]” value=”{$category}” />{$category}</li>

<p>                       <br />

{/foreach} Keywords: notes, code</p>

Keywords: notes, code


PHP: To turn off only warnings and still show errors

Use the following line on your code:


You can also turn it off on your php.ini file (not recommended):

error_reporting = E_ERROR


PHP: Do not use fopen() to read XML files into xml_parse(

was using the following function to get a xml url from the web, create a handle,  read the content, and then feed it to xml_parse():

if (!($fp = fopen($xml_file, ‘r’))) {              die(’Cannot open XML data file: ‘.$xml_file);

return false;


$bytes_to_parse = 1024;

while ($data = fread($fp, $bytes_to_parse)) {            $parse = xml_parse($this->xml, $data, feof($fp));

if (!$parse) {

die(sprintf(”XML error: %s at line %d”,                    xml_error_string(xml_get_error_code($this->xml)),

xml_get_current_line_number($this->xml)));                        xml_parser_free($this->xml);

}        }

The problem in doing this, is that the 1024K bytes that gets read in every loop of the while may cut out content.

For example, I was capturing the following xml file:

And this is what I was getting:

2006-09-14 15:37:15,699 DEBUG> /dump/include/class.xmlparser.php:40 parse  – This is $data:

29:49       This week: Tech news, new products from Apple, LCD versus Plasma, and reader questions.

Wed, 13 Sep 2006 05:25:00 EDT

Tom Holcomb and J.D. Biersdorfer of The New York Times              2006-09-14 14:32:24,424 DEBUG> /dump/include/class.xmlparser.php:38 parse  – This is $data: uration>25:51

This week: Tech news, online file storage and reader questions.

Wed, 06 Sep 2006 04:43:00 EDT

Tom Holcomb and J.D. Biersdorfer of The New York Times


This week: Tech news, online movie downloads, and reader questions.

Wed, 30 Aug 2006 04:00:00 EDT

2006-09-14 14:32:24,426 DEBUG> /dump/include/class.xmlparser.php:38 parse  – This is $data: closure length=”26584293″ url=”″ type=”audio/mpeg”/>

Notice how the xml file was being cut in several parts, and the beggining of some tags was being included in one section, while the closing of the same tag was included on the next.

Switching to this code solved the problem:

$file_handle = file_get_contents($_POST[’rss_url’]);                         $myFile = new XMLParser($file_handle);

$arr = $myFile->ParseChannelFromXML();

function parse($xml_file)    {

$parse = xml_parse($this->xml, $xml_file);            if (!$parse) {

die(sprintf(”XML error: %s at line %d”,                    xml_error_string(xml_get_error_code($this->xml)),

xml_get_current_line_number($this->xml)));                        xml_parser_free($this->xml

);            }

return true;


Now the entire XML file is read once, instead of in several smaller parts, and therefore no cut off happens.