How to solve encoding problem in PHP?
Submitted by sajjad.f.r on Fri, 05/11/2012 - 10:18This is a small note for mine and for those who has also fallen in similar situation. I was trying to save non-English characters, but my browser can't show them properly. After digging here and there, I got a way around.
1. First encode your string with htmlentities($string,ENT_IGNORE,'UTF-8')
2. Use a function to double check UTF-8 encoding, if the string is not UTF-8 encoded, do it then using the follow function:
//returns true if a string is UTF-8 encoded
function isUTF_8($string)
{
return (@iconv('utf-8', 'utf-8//IGNORE', $string) == $string);
}
PHP get_browser
Submitted by sajjad.f.r on Tue, 05/08/2012 - 16:53Today, while working I found my script is not working properly for get_browser(null, true) in PHP. This function has problem with 'parent' parameter. So I checked the browscap, and it says there is a newer version is coming on 7th May, 2012. Here is the link Browscap.ini
Download the file and enjoy your work!! It has extra device parameters now.
MySql Export to CSV
Submitted by sajjad.f.r on Wed, 04/25/2012 - 13:14I was working on a project where I needed to create CSV output file from MySql. So I found something and made it working for me in this way:
mysql -u username -p password database_name -B -e "query" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > path_to_csv/filename.csv;
username, password, database_name, query: user defined
-B : will print row in every new line
-e: will execute the query
I hope it will help other people too.
Installation of MongoDB with PHP
Submitted by sajjad.f.r on Sat, 06/11/2011 - 20:43How to setup database (MongoDB)
Step 1: Download the latest version from here for OSX (32 bit or 64 bit) accordingly:
http://www.mongodb.org/display/DOCS/Downloads
Step 2: run this: mkdir -p /data/db/
Step 3: untar the downloded file here: /Applications/MAMP/db/
Step 4: There should be a bin folder in the unzipped folder. Run this to start server:
cd ./bin/mongod
If the mongo server starts, you can access it from here:
http://localhost:28017/
and can check by running command: ./mongo
This will show you MongoDB version and few more information.
Issue:
Code Igniter 2.0 layout and extending controller
I have setup cake php like codeigniter 2.0 in my server. There is also problem with .htaccess in hostmonster. So I also changed .htaccess accordingly for codeigniter. It works like a charm in every server.
Try this and I will be happy to have any kind of feedback.
Code Igniter 2.0 with Layout
Good Luck!
