2009/11/27 16:28

PHP function converts new line to BR tag


In case of displaying normal text having CR+LF character string on web browser, you may need to change it to <BR> tag.

PHP provides speedy converting function for supporting that. Following function is very useful.

Proto-type:
function nl2br( <source string> )

As you can expect by function name, it converts new line character set to <BR> tag.

Example)

.
.
.
$buf = nl2br( $source_string);
echo $buf;

Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.

2009/10/19 16:01

PHP socket programming to get content with post method


When you need to get content with POST Method in PHP internal code, you need to get the desired result through alternate Socket Programming as below.

Actualluy what I wanted is emailing through alternate server located in different domain, because the current server has some limitation.

Following code is implemented at caller server.
<?
// caller page : kmail.php
// programmed by Super Coder / Chunun Kang (kurapa@kurapa.com)
function kmail( $recipient, $subject, $body)
{
  $host = "foo.com";
  $uri = "/api/kmail_api.php";

  // acutally security code is removed on below code.
  // you can add it by yourself.
  $reqbody = "s=" . urlencode($subject)
           . "&b=" . urlencode($body)
           . "&f=" . urlencode('SAMSUNGDForum')
           . "&h=" . urlencode($headers)
           . "&r=" . urlencode($recipient);

  $contentlength = strlen($reqbody);
  $reqheader = "POST $uri HTTP/1.0\xd\xa".
  "Host: $host\xd\xa". "User-Agent: Mozala\xd\xa".
  "Content-Type: application/x-www-form-urlencoded\xd\xa".
  "Content-Length: $contentlength\xd\xa\xd\xa".
  "$reqbody\xd\xa";
  $socket = fsockopen($host, 80, $errno, $errstr);
  if (!$socket)
  {
    $result["errno"] = $errno;
    $result["errstr"] = $errstr;
    return $result;
  }
  fputs($socket, $reqheader);
  while (!feof($socket))
  {
    $result[] = fgets($socket, 4096);
  }
  fclose($socket);
  return $result;
}
?>


In addition you need to add following callee PHP page on your callee server.
<?
    // callee page : /api/kmail.php
    // programmed by Super Coder / Chunun Kang (kurapa@kurapa.com)

    $title = '=?utf-8?b?'.base64_encode($s).'?=';
    $recipient = $r;

    if (strlen($h)<1)
    {
      if (strlen($f)>0)
      {
        $h = "From: $f <no-reply@foo.com>\r\n";
      }
      else
      {
        $h = "From: NO-REPLY <no-reply@foo.com>\r\n";
      }
      $h .= "X-Sender: no-reply@foo.com\r\n";
      $h .= "X-Mailer: Mozala PHP ".phpversion()."\n";
    }
   
    mail($recipient , $title, $b, $h);
?>


Finally what you need to do is including above caller page to call kmail function.

include "./kmail.php";
kmail( "foo@foo.com", "howdy?", "test message from Chunun Kang (kurapa@kurapa.com");

Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.

2009/10/15 14:42

How to get process id in C# like windows task manager ?


Following is simple example to get Process name and add Process name to listbox control.

As you can see below, you can get working Process by Process control. But most of the properties are supported on windows platform. If you want to access the similar properties on windows mobile, you need to use another function.

using System.Diagnostics;

.
.
.

            Process[] prs = Process.GetProcesses();

            listBox1.Items.Clear;
            foreach( Process pr in prs)
            {
                listBox1.Items.Add( pr.ProcessName);
            }

Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.

2009/09/14 20:03

Photoshop script programming in Javascript


Adobe Photoshop provides the strong functions as javascript function for extension. In case of developing web based photo editing application, you can use it with javascript easily.

Follwing is the first step to use Photoshop Scripting:

<script>

if (BridgeTalk.appname == "Photoshop")
{
  // then you can do something for photo
}

</script>

As you can see above, you can simply check whether Photoshop Script is available or not.
Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.

2009/09/09 08:03

Is there directory selection VCL component in Delphi ?


There are FileOpenDialog and FileSaveDialog components on Delphi VCL.
Sometimes you may need Directory Selection dialog, but no components are found on VCL.
Do you know Delphi provides the solution as SelectDirectory().

Here are two examples for Directory Selection.

Following shows directory structure under d:\delphi
procedure TForm1.Button1Click(Sender: TObject);
var
  DirSelected: string;
begin
  if SelectDirectory('Select a folder:', 'D:\Delphi', DirSelected) then
    ShowMessage('You selected ' + DirSelected)
  else
    ShowMessage('You did not select a folder');
end;


Following shows driver names and files as well as directory structure.
procedure TForm1.Button2Click(Sender: TObject);
var
  Dir: string;
begin
  Dir := 'D:\Delphi';
  if SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt], 0) then
    ShowMessage('You selected ' + Dir)
  else
    ShowMessage('You did not select a folder');
end;

Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.