Monday, September 19, 2011

Convert String to Hexadecimal in PHP

bin2hex($string) will solve this problem. Don't get confused by the word bin in the function.

When I searched for converting a string to hexadecimal, in most of the blogs/Forums i got the following function.

function strToHex($string)
{
    $hex='';
    for ($i=0; $i < strlen($string); $i++)
    {
        $hex .= dechex(ord($string[$i]));
    }
    return $hex;
}

But when i tried to compare the output of above function with bin2hex (inbuilt PHP function), both got the same result.

Conclusion is if you want to convert a string into an hexadecimal string, then it's better to use bin2hex insted of the above function.

I tested it with the following example
"sfkjsd38jsdkjfD83kkksJADHAJ#$#JDKEHdjh843j4hjkDS&@)HDHSJKDHADASDSWE(Y#JDHSA*&#JKD3423523Sd"

Wednesday, August 3, 2011

Mutli Dimensional Array to Object and vice versa

Even though this is a simple logical program just want to post it here

function arrayToObj ($data)
{
if (is_array($data)) {
foreach ($data as $key => $value) {
$data[$key] = arrayToObj($value);
}
$obj = (object)($data);
return $obj;
}
return $data;
}

and the opposite is

function objToArray ($data)
{
if (is_object($data)) {
$array = (array)($data);
} else {
$array = $data;
}
if (is_array($array)) {
foreach ($array as $key => $value) {
$array[$key] = objToArray ($value);
}
return $array;
}
return $array;
}

Wednesday, March 9, 2011

Soft skills to move ahead


Again I am copying the content from some other source, definitely will come up with my own content soon.

Tuesday, March 8, 2011

brief overview about PHPUnit (for starters)

I got these slides from Mike Lovely (mjlivelyjr - slideshare account name)

Tuesday, January 18, 2011

SVN obstructed key word meaning

if you find obstructed keyword against any directory when you check for modifications of your current working directory.
Follow the following steps to resolve this issue.
(let's assume the directory name is codeRepo)
1) Rename the directory (codeRepo to codeRepo_bkup)
2) Cleanup the entire svn folder.
3) Now do the svn update, the folder get added to your code (means codeRepo folder is added again)
4) Now copy all the files from backup directory (codeRepo_bkup) and paste them in current svn directory (codeRepo), so that you will not miss any changes that you made.
5) And now you can delete the backup file (remove codeRepo_bkup)

The root cause of this is adding or removing a current svn directory from any other sources(like eclipse etc) other than from folder.

Thursday, October 28, 2010

1030 - Got error 28 from storage engine - MySQL error

Hi back after long time. Want to keep in touch regularly from today onwards.

Today I got this error when i imported a new code into my M/C.
after importing the code i am unable to do any operations. For every operation on mysql it is throwing this error.
So i am unable to access my local sites too as the mysql is not working.

The cause for this error is the disk space. I had deleted the newly imported code from the system, then this issue got resolved. Means we need to delete unwanted files or we need to add extra space.

Wednesday, August 4, 2010