Category Archives: PHP

nl2br, new line to br

I just forget this function when my friend ask me about strangeness in his data he store in mysql.

He has address data in <textarea></textarea>, new line not converted to br as he thing. He just see all the input just store in single line.

After search for a while I remember this gold function :

nl2br () , new line to br

just make temporary variable before as :


now $address will contain <br> tag in mysql database.

This post for remind me in future đŸ˜‰


php explode() and wordwrap()

Whats the different of explode() and wordwrap() ?

Answer :

just see this example for explode()



//we need to split the component to date, month and year


// we use – as tool to separate, now print





Wordwrap will ‘wrapping’ user input, like formatting crazy user who type ‘aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa’ till he satisfied and brake our guestbook table.

Just make sure to add number bigger than 0 to enable wordwrap.

101 CodeIgniter Resources

CodeIgniter already attract my attention since version 1.5, we even try to build application based on it.

Beside its clear documentation, their user support awesome too.

I’ll try to collect every resource that might useful to share with others who want to learn codeigniter.

This post will be update regularly as soon as I get another resource :-)

CodeIgniter Main Page

1. Download site

2. User Guide

3. Wiki

4. Forum

CodeIgniter Video Tutorials

1. Hello world, introduction to CodeIgniter

2. Create a blog in 20 minutes

3. Derek Allard Video

CodeIgniter Books

1. CodeIgniter for Rapid PHP Application Development

CodeIgniter Tutorials

1. Introduction to Code Igniter: Part 1 by Godbit, learn about CI structure. starting the case of making form.

2. Introduction to Code Igniter: Part 2 by Godbit, form continued.

3. Introduction to Code Igniter: Part 3 by Godbit, CI interact with database.

4. Pagination with Code Igniter by Godbit, make navigation easy with paging in CI.

5. Code Igniter Template Tutorial by Eric Barnes, separate logic with presentation.

6. Templating with CodeIgniter, templating study case.

7. Using Zend Framework components in Code Igniter, integration zend framework into CI.

8. Building an RSS Feed in Code Igniter, Derek Allard show howto build RSS with CI.

9. Using Oracle with PHP and CodeIgniter, Oracle and CI teamed together. I use oracle xe instead.

10. Forms in CodeIgniter Views, use don’t repeat yourself concept :-)

11. Checking CodeIgniter out of the Subversion Repository, Derek show how to use subversion of CI.

12. SimplePie RSS class and CodeIgniter, simplepie and CI work together.

13. Building a Complete CodeIgniter Application: Part 1, by Jim OĂ¢â‚¬â„¢Halloran. Build feedignitation from scratch.

14. Building a Complete CodeIgniter Application: Part 2, by Jim OĂ¢â‚¬â„¢Halloran.

15. Building a Complete CodeIgniter Application: Part 3, by Jim OĂ¢â‚¬â„¢Halloran. Eliminate security problems.

Last Update : January 09 2008

Latest news : Code Igniter 1.6 released!, read more from DerekAllard blog.

Make lowercase followed by uppercase data

Question :

I have table A with field id, name and address. The data in name field seem not consistent, big letter name sometime found in record. How to update that field with uppercase in name field. For example :

                 id              name                                       address

                 1               FreAKHolicz  wORker            the moon

                 2              tHE atMOSFER bluEZ            nowhere

FreAKHolicz  wORker must change to Freakholicz Worker

Answers :

1. Looping

2. Use strtolower() function followed by ucwords() function.

example code :


$query=mysql_query("select id,name from table A");



//change to lower case

$name1=strtolower($name); // will make FreAKHolicz  wORker  into freakholicz worker

//change to uppercase

$name2=ucwords($name1); // will make freakholicz worker into Freakholicz  Worker

//now using $name2 as variable to update name field

$update=mysql_query("update A set name=’$name2′ where id=’$id’");



since it’s looping, all good record also examined by scripts until no record left, using another conditional condition would bring another result.

P.S :

  • Use ucfirst() to change only first alfabet
  • Its possible using many function in one operation such as :  $name2=ucwords(strtolower($name));

Export picture from mysql database to file

As our data getting mobile and copying picture is annoying for me I decide to save the picture in the database (mysql).

Another challenge came when other division need the data exported in a directory with same dimension (135 x 180 pixel).

Structure for table ‘student_pic’  :

CREATE TABLE `student_pic` (
  `image_id` int(10) unsigned NOT NULL auto_increment,
  `username` varchar(50) NOT NULL default ”,
  `image_type` varchar(50) NOT NULL default ”,
  `image` longblob NOT NULL,
  `image_size` bigint(20) NOT NULL default ‘0’,
  `image_name` varchar(255) NOT NULL default ”,
  `image_date` datetime NOT NULL default ‘0000-00-00 00:00:00’,
  UNIQUE KEY `image_id` (`image_id`)

Yes, I use mysql 5 ( 5.0.45)

Continue reading