Archive for the ‘PHP’ Category

Terminal Apache/PHP/MySql

Sunday, August 8th, 2010

Terminal.

Check the version of Apache : https – v

Apache restart : sudo apachectl graceful

Apache stop : sudo apachectl stop

Apache start : sudo apachectl start

PHP

Check the version of PHP : php -v

Check this post when php doesn’t work properly.

MySql

Check  MySql version : mysql –version (usr/local/mysql/bin/mysql)

Export Path : echo ‘export PATH=$PATH:/usr/local/mysql/bin’ >> ~/.bash_profile

Export Path Check : cat .bash_profile

Setup Root Password : sudo mysql_secure_installation

Add GetBundle to TextMate and using WordPress Bundles

Tuesday, March 2nd, 2010

Related Link :

Additional Report :

If you don’t have TextMate folder, Just make under Library/Application Support/TextMate/Bundles
ex : mkdir -p /Library/Application\ Support/TextMate/Bundles

Zend Debugger using MAMP Pro

Thursday, February 18th, 2010

1. Open MAMP Pro and go to File > Edit Template > PHP5 php.ini
2. add below : Make sure path is correct

[xdebug]
zend_extension=”/Application/Zend/Zend Studio for Eclipse – 6.1.1/
plugins/org.zend.php.debug.debugger.macosx_5.2.15.v20080907/
resources/php5/ZendDebugger.so”

3. Open Zend Studio and go to Preferences > PHP > PHP Executables

4. Add Executable path ex : /Applications/MAMP/bin/php5/bin/php

Original Document

PHP Study 01

Sunday, February 7th, 2010

Default Syntax

<h3>Hello</h3>
<?php
echo "<p>out put sentence</p>";
?>
<p>normal sentence</p>

Short-Tags

<?
print "Wha ha ha ha";
?>
<?="Wha ha ha ha.";?>
<? echo "Wha ha ha ha."; ?>
<?php echo "Wha ha ha ha.";?>

Script

<script language="php">
print "Wha ha ha ha.";
</script>

Embedding Multiple Code Blocks

<html>
       <head>
              <title><?php echo "Welcome to sangpil.net!";?></title>
       </head>
       <body>
       <?php
              $date = "Feb 7, 2010";
       ?>
       <p>Today's date is <?=$date;?></p>
       </body>
</html>

Commenting

<?php
// Title: My first PHP
// Author: Sangpil Hwang
echo "Nice to meet you";
?>
 
<?php
# Title: My first PHP 
# Author: Sangpil Hwang
echo "Nice to meet you";
?>
 
<?php
/*
Title: My PHP API
Author: Sangpil, Hwang
Date: Feb 7, 2010
*/
?>

print

int print(argument)

<?php
        print("<p>print my sentence</p>");
?>
<?php
        $txt = "hallo";
        print "<p>I say $txt.</p>";
?>

echo

void echo(string argument1 [, ...string argumentN])

<?php
        $val_1 = "item 1";
        $val_2 = "item 2";
        echo $val_1, " and ", $val_2, " are my items.";
?>
 
<?php
        $val1 = "1.2e3"; // 1,200
        $val2 = 2;
        echo $val1 * $val2; // outputs 2400
?>

printf

boolean printf(string format [, mixed args])

printf("inventory: %d little rabbits.", 100);
printf("%d little rabbits cost $%f" £, 100, 10.80);
printf("$%.2f", 43.2); // $43.20

Type Description
%b Argument considered an integer; presented as a binary number
%c Argument considered an integer; presented as a character corresponding to that
ASCII value
%d Argument considered an integer; presented as a signed decimal number
%f Argument considered a floating-point number; presented as a floating-point number
%o Argument considered an integer; presented as an octal number
%s Argument considered a string; presented as a string
%u Argument considered an integer; presented as an unsigned decimal number
%x Argument considered an integer; presented as a lowercase hexadecimal number
%X Argument considered an integer; presented as an uppercase hexadecimal number

sprintf

string sprintf(string format [, mixed arguments])

$cost = sprintf("$%.2f", 43.2); // $cost = $43.20

String

$col = "blue";
$parser = $col[2]; // Assigns 'u' to $parser

Array

$state[0] = "Data1";
$state[1] = "Data2";
$state[2] = "Data";
 
$state["Sangpil"] = "male";
$state["Sohyun"] = "female";
$state["Minsu"] = "male";

Object

class MyClass {
        private $_myVal;
        function settedFunction($myParam) {
                $this->_myVal = $myParam;
        }
}
$myInstance = new MyClass;
 
setPower():
$myInstance->settedFunction("go");

Type Casting

$num = (double) 12; // $num = 12.0
$num = (int) 14.8; // $num = 14
$sentence = "This is a sentence";
echo (int) $sentence; // returns 0
 
$score = 1114;
$scoreboard = (array) $score;
echo $scoreboard[0]; // Outputs 1114
 
$model = "samsung";
$obj = (object) $model;
print $ obj->scalar; // returns "samsung"