Binary Expressions

Next Page »

2007-11-16

French Characters Not Rendering Correctly

Filed under: — The Warden @ 9:13 am

Background Knowledge


The MySQL database v4.0.23 is using the default character set of “Latin1″. When the database was created I had no knowledge of character sets other wise it would have been “UTF-8″.
The web pages are using a character set of “UTF-8″.

Problem


Data being queried from a MySQL database that contains French accent characters will not render correctly in the browser even after applying PHP htmlentities().

Example code: $string = htmlentities($string , ENT_QUOTES, “UTF-8″);

Solution


The queried data from the database was inputted using the character set “ISO-8859-1″. I found this out by changing the browser’s character encoding to “Western ISO-8859-1″ and the French accent characters then rendered properly. With the use of PHP iconv() I was able to convert the data from “ISO-8859-1″ to “UTF-8″ character set and the French characters then rendered properly in the browser.

Example code: $string = iconv(”ISO-8859-1″,”UTF-8″,”$string”);


If you are unaware of what MySQL default character set being used, you can run this SQL command “show variables like “%character%” and check your MySQL configuration file. Refer to the MySQL manual for further details.

2007-11-8

HTML_QuickForm Generates Invalid Code for XHTML Strict

Filed under: — The Warden @ 4:18 pm

One of the biggest complaints I’ve had with HTML_QuickForm is not producing valid XHTML Strict code. Well there is a simple solution to removing the name attribute of the HTML form element tag using remoteAttribute().

Example
$form->removeAttribute(’name’);

2007-11-1

PHP Calendar Functions Error

Filed under: — The Warden @ 11:56 am

I was trying to use the PHP calendar API and immediately received this error message, “Fatal error: Call to undefined function cal_days_in_month()”. This error message means PHP was not compiled with the calendar extension.

Solution


The only solution to this error message and other similar error messages relating to the PHP calendar API requires PHP to be compiled with the calendar extension by adding “–enable-calendar” to the “configure command” as stated in the PHP documentation on the Calendar functions page.

How to Tell if the Calendar Extension is Installed


You can verify weather or not the PHP Calendar extension was compiled at install by using the phpinfo() function. When viewing the output of phpinfo() look under “Configure Command” just below “Build Date” and if you do not see “–enable-calendar” present then all PHP Calendar functions will not work.

Configure Example


./configure –with-mysql=/usr/local –with-mssql=/usr/local –with-apxs –with-zlib-dir=/usr/lib –with-libxml-dir=/usr/local –with-config-file-path=/var/www/conf –with-iconv=/usr/local/bin/iconv –enable-exif –-enable-mbstring –enable-calendar

2007-10-17

PHP Free Chat - Joining Chat Email Notification

Filed under: — The Warden @ 2:50 pm

I recently upgraded an install of PHP Free Chat to that latest version of 1.0 Final. However it was still lacking a feature to notify individual(s) that someone has joined the chat if they were not already in the chat application to begin with. I came across a posting explaining how to achieve this in PHP Free Chat at PHP Free Chat Forum. After a little reading and discussion I was able to implement the feature.

Here’s my modified version for the solution based on the forum posting. The pfcmail() function can be made to be way more versatile for any use, however for my use it was made to be simple and produce properly formated email messages.

Solution


  1. Create a new PHP file called pfcmail.php with the following lines of code.
  2. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    
    < ?php
    function pfcmail($szChannel,$szNickname)
    {
    	$szCurrentDateTime = date('F j, Y @ g:i:sa', time());
    	$szClientIP = getenv("REMOTE_ADDR");
    	$szHostName = gethostbyaddr("$szClientIP");
    	$szServerName = getenv("SERVER_NAME");
    	$szEmailWebmaster = getenv("SERVER_ADMIN");
     
    	$szEmailTo = "Webmaster <$szEmailWebmaster>";
    	$szMsgHeaders = "From: $szEmailWebmaster\r\n";
    	$szMsgHeaders .= "X-Mailer: PHP\r\n";
    	$szMsgHeaders .= "MIME-Version: 1.0\r\n";
    	$szMsgHeaders .= "Content-type: text/plain; charset=UTF-8";
    	$szMsgSubject = "[WEB] Chat Login - $szNickname in channel $szChannel at $szCurrentDateTime";
     
    	$szMsgBody = "Date\t\t\t\t: $szCurrentDateTime\n";
    	$szMsgBody .= "Server Name\t\t\t: $szServerName\n";
    	$szMsgBody .= "Client IP\t\t\t: $szClientIP\n";
    	$szMsgBody .= "Client Hostname\t\t: $szHostName\n\n";
     
    	$szMsgBody .= "Join chat now by going to http://$szServerName/chat/index.php.\n\n";
     
    	$szMsgBody .= "---\n";
    	$szMsgBody .= "Email message auto-generated by PHP mail().";
     
    	$nSendEmail = mail($szEmailTo, $szMsgSubject, $szMsgBody, $szMsgHeaders);
    }
    ?>
    Note: The extra r, n and t’s should have a \ character before them to produce a carriage return, new line and tab. WordPress appears to remove the character.
  3. Make sure to modifiy the code in pfcmail.php for the To, from, subject and body of the email message to your requirements.
  4. Save pfcmail.php file into the following path, /src/commands/.
  5. Edit /src/commands/nick.class.php at line number 84, just before “return true;” add the following code and save.
  6. require_once(dirname(__FILE__).”/pfcmail.php”);
    pfcmail($c->title, $newnick);

You should now be receiving email notifications each time an individual joins chat.

2007-7-10

PEAR::HTML_BBCodeParser Upgrade 1.1 to 1.2.2

Filed under: — The Warden @ 12:54 pm

Problem #1 - “[notice] child pid 13449 exit signal Segmentation fault (11)”

On a OpenBSD v3.7 i386 system running Apache v1.3.29 (not chrooted) with PHP v5.1.4 I upgraded HTML_BBCodeParser from version 1.1 to version 1.2.2 by running at command line “pear upgrade-all”. After the upgrades were complete the web site would not load a web page anymore. I looked at my HTTPD server logs and noticed I was receiving the following error message in error_log file, “[notice] child pid 13449 exit signal Segmentation fault (11)” whenever there was a HTTP request on port 80 or 443 to the web site. I couldn’t understand what the problem could be but then decided to uninstall HTML_BBCodeParser v1.2.2 and re-install HTML_BBCodeParser v1.1 to see if the web site would still function. Indeed the web site did load and function fine. So I decided to uninstall and install each version up to v1.2.2 to see where the breaking point was. As soon as the latest version of HTML_BBCodeParser v1.2.2 is installed the web site stops functioning. I was able to determine that there was something that has changed in v1.2.2 or something I did wrong in the Filters I created and existing filters I altered.

Solution #1

I uninstalled HTML_BBCodeParser then manually removed the directory /usr/local/lib/php/HTML/HTML_BBCodeParser. Then I installed HTML_BBCodeParser v1.2.2 and copied the BBCodeParser.ini example from /usr/local/lib/php/doc/HTML_BBCodeParser/BBCodeParser/example/ to /usr/local/lib/php/HTML/BBCodeParse/. After that the web site functioned as normal again.

Problem #2 - “Warning: strpos() [function.strpos]: Empty delimiter.”

However I discovered that when using PHP 5 one has to alter the BBCodeParser.ini file otherwise you will receive the following warning message when trying to load a web page using HTML_BBCodeParser, “Warning: strpos() [function.strpos]: Empty delimiter. in /usr/local/lib/php/HTML/BBCodeParser.php on line 354″.

Solution #2

Edit your BBCodeParser.ini and alter the line for the opening tag character and closing tag character to be enclosed by double quotes around the square brackets, [ and ]. Apparently this has been an issue for awhile now, http://pear.php.net/bugs/bug.php?id=2580.

Example After Alteration - BBCodeParser.ini

[HTML_BBCodeParser]

; possible values: single|double
; use single or double quotes for attributes
quotestyle = single

; possible values: all|nothing|strings
; quote all attribute values, none, or only the strings
quotewhat = all

; the opening tag character
open = "["

; the closing tag character
close = "]"

; possible values: true|false
; use xml style closing tags for single html tags ( or )
xmlclose = true

; possible values: a comma seperated list of filters
; comma seperated list of filters to use
filters = Basic,Extended,Links,Images,Lists,Email

2007-4-18

PEAR::HTML_BBCodeParser Parser Issue

Filed under: — The Warden @ 4:01 pm

I’ve come into a situation where I require to have BBCode parsed, this includes the standard tags supported by PEAR package HTML_BBCodeParser and custom BBCode tags I’ve added myself.

My problem is this, I’ve discovered that when an value has a space within the value the value is truncated at the first occurrence of the space. This applies to a URL, image file names and any additional attribute values (alt, style, etc.). This issue is present in the stable release and latest release in CVS for HTML_BBCodeParser. Here is some examples.

Before BBCode Parser
   [url=http://www.somedomain.com/Foo World?str=1]Foo World
After BBCode Parser
   <a href="http://www.somedomain.com/Foo">Foo World</a>

Before BBCode Parser
   [img w=100 h=99 alt=Enthalpy Wheel]/images/Enthalpy Wheel.png[/img]
After BBCode Parser
   <img src="/images/Enthalpy" width="100" height="99" alt="Enthalpy" />

Before BBCode Parser
   [p style=foo bar]something here[/p]
After BBCode Parser
   <p style="foo">something here</p>

Before BBCode Parser
   [div style=color:blue; font-size: 1em;]something here[/div]
After BBCode Parser
   <div style="color:blue;">something here</div>

This problem appears to exist across the board even without additional BBCode tags or additional attributes.

Any suggestions or directions on how I can resolve this problem would be much appreciated.

2006-7-28

Default Timezone in PHP, Not Working?

Filed under: — The Warden @ 2:13 pm

Since I started using PHP 5.x.x I started to experience incorrect time reported back through PHP using for example date(). I checked phpinfo() and found out that the default timezone was detected as America/Chicago. This was not the case as the server was configured for Canada/Saskatchewan (CST). I found out that I ended up having to directly set my timezone in php.ini file. I put the following in my php.ini file, then restarted Apache and the problem was resolved.

date.timezone = “Canada/Saskatchewan”

I’m not sure if this is a bug in PHP not detecting the timezone correctly. I tried searching through known PHP Bugs but no luck locating my problem. By the way, I’m running Apache with PHP/MySQL on OpenBSD i386 v3.7.

Thanks to TML from IRC channel ##php on freenode for helping me resolve the problem.

2006-6-7

Common Mistake - Echoing an Array

Filed under: — The Warden @ 11:29 am

I’m sure most would agree when one does a programming mistake they are a lot of times trivial mistakes. However when one stares at the code for long periods of time we seem to go blind and then in the process of frustration loose all logically thinking as to what could be causing the problem. Here is one such problem with arrays.

  • Problem
  • The value of the Array is not rendering. Instead you see array[0].
  • Solution
  • Remove your single or double quotes around the variable representing the array. When one places single or double quotes around the array you are causing it to be treated as literal.

    2006-6-5

    PHP - Populate HTML Select Element

    Filed under: — The Warden @ 2:00 pm

    There is many ways to populate vales into a HTML select element. Here is one example I’ve come up with.

    PHP Code Example

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
    <select size="1" name="szFooBar[]" multiple="multiple">
    < ?php
    $i=0;
    while($obResults = mysql_fetch_row($saResults))
    {
        if ($_POST['szFooBar'] == $obResults[0])
        { $szSelectedValue[$i] = " selected=\"selected\""; }
        else { $szSelectedValue[$i] = ""; }
     
        printf("<option value=\"%s\"%s>%s\n",$obResults[0], $szSelectedValue[$i], $obResults[1]);
        $i++;
    }
    ?>							
    </select>

    2005-8-9

    PHP/MySQL Query Example

    Filed under: — The Warden @ 3:25 pm

    A basic MySQL query using PHP with commenting marked with //.

    // SQL statement that will be sent to the MySQL database server.
    $szQry = “SELECT column1, column2 FROM foo”;

    // MySQL database login credentilas; host (127.0.0.1), username and password.
    $szDBConn = mysql_connect(”host”,”username”,”password”);

    // Select database using the login credentials provided above.
    mysql_select_db(”database_name”, $szDBConn);

    // Send SQL statement to database.
    $saResults = mysql_query($szQry, $szDBConn);

    // Fetch results retured back from the SQL statement.
    $obResults = mysql_fetch_row($saResults);

    MySQL Lost connection to MySQL server during query

    Filed under: — The Warden @ 12:41 pm

    For more than 3 hours I’ve been trying to find a solution to the error I kept receiving when doing a basic query to MySQL through PHP. It kept returning back to me “Lost connection to MySQL server during query”. Right away I went to my PHP, MySQL and Apache logs to find more information. I came back with nothing more than the error message I already received. So as I usually do off I went to Google and IRC for some help. Neither were leading into any direction to a solution. Even after finding the MySQL documentation talking about the “Lost Connection” or “server has gone away” error I didn’t find a solution. I started talking to dhartmei on EFNet in the #OpenBSD channel for some assistance. He stepped me through doing the following at the command prompt.

    # nc -v 127.0.0.1 3306
    Connection to 127.0.0.1 3306 port [tcp/mysql] succeeded!
    Host ‘localhost.domain.com’ is not allowed to connect to this MySQL

    # netstat -an | grep 3306
    tcp 0 0 *.3306 *.* LISTEN

    # mysql -h 127.0.0.1 -u username -p database
    Enter password:
    ERROR 2013: Lost connection to MySQL server during query

    This determined that port 3306 was listening for connections however localhost/127.0.0.1 returned an error message of “Host ‘localhost’ is not allowed to connect to this MySQL”. If you haven’t caught on already this means I forgot to set MySQL permissions correctly for the user. Remember that localhost and 127.0.0.1 is different according to MySQL permissions.

    A quick GRANT (i.e. grant all ON database.table TO username@localhost identified by ‘password-here’) command in MySQL resolved the problem.

    2005-7-20

    How to Install PHP from Source

    Filed under: — The Warden @ 2:01 pm

    This installation example for Unix/Linux installs dependency support for Midgard CMS. Make sure Expat, zlib (comes with OpenBSD) and iconv are installed before proceeding. I have added additional configuration for MySQL (so the correct MySQL libraries are used), Microsoft SQL Server, apxs, XML, exif, dba and mbstring. Refer to the PHP configurator for details (# ./configure –help).

    # ./configure –with-mysql=/usr/local –with-mssql=/usr/local –with-apxs –with-xml –with-zlib-dir=/usr/lib –with-expat –with-config-file-path=/var/www/conf –with-iconv=/usr/local/bin/iconv -–with-exif –-with-dba –-with-mbstring
    # make
    # make install
    # make clean
    # cp php.ini-recommended /var/www/conf/php.ini

    Review/edit /var/www/conf/php.ini (path may vary) file to match your requirements. To meet the requirements of Midgard CMS you will require to do the following.

    Add extension=midgard.so into your php.ini file.
    Add the extensions path to extension_dir. Type “php-config –extension-dir”. Place the returned path into your php.ini file.
    Ensure the file_uploads=on.
    Ensure the short_open_tag=on.

    Next Page »

    Take back your mailbox - CAUCE.org

    Powered By Wordpress PHP: Hypertext Preprocessor MySQL Powered Download Juice, the cross-platform podcast receiver
    Proud To Be Canadian Get Firefox Valid XHTML Valid CSS
    <NO>OOXML Logo


    26 queries. 0.566 seconds.
    Copyright © 2004 - 2005 by Adam Douglas