Search results for 'PHP'. 50 post(s) found.

  1. 2009/11/27 PHP function converts new line to BR tag
  2. 2009/10/19 PHP socket programming to get content with post method
  3. 2009/08/05 How to remove HTML tags in text string?
  4. 2008/10/01 How to delete file on certain path ?
  5. 2008/09/23 ASCII Artwork Generator from image file
  6. 2008/04/14 How to limit by Timeout when opening URL ?
  7. 2008/03/31 How to put timeout when opening URL by fopen ?
  8. 2008/02/28 How to convert W3C Date Time Format ?
  9. 2008/02/24 Get the actual filesize for a size above 2GB in Windows
  10. 2008/02/13 ISO 8601 format time format string conversion
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/08/05 13:42

How to remove HTML tags in text string?


strip_tags() function is the simplest & fast PHP function to remove HTML Tags in text string.

Here's the simple example.

      $m_school = strip_tags( $m_school);


Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.

2008/10/01 16:45

How to delete file on certain path ?


The file deletion function is really simple. It's exactly the same with C function.
Following is the example.

Unlink( 'c:/hello.world.txt');

Trackback 3 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject Animal sex dvd.

    Tracked from Animal sex. 2009/02/12 12:32 delete

    Animal sex videos. Free animal sex video. Free animal sex. Askjolene com gay animal sex.

  2. Subject Lesbian incest.

    Tracked from Incest. 2009/03/12 11:11 delete

    Young incest stories. Incest porn. Incest story.

  3. Subject Vicoden valium.

    Tracked from Buy valium c.o.d.. 2009/06/14 13:31 delete

    Valium side effects. Valium picture. Cheap valium. What does valium look like. Valium. Valium without prescription.

2008/09/23 07:55

ASCII Artwork Generator from image file


Now a days, we don't use ASCII Artwork usually for internet communication, because technology is changing rapidly.

Following snipet is the really great source can generage ASCII Artwork from image file such as jpeg or gif.

<?php
     $filename = $_POST['file'];

     $image = file_get_contents($filename);

     $image = imagecreatefromstring($image);

     $width = imagesx($image);
     $height = imagesy($image);

     $m_aspect = 164.0 / 48.0;
     $i_aspect = $width / $height;

     if($i_aspect < $m_aspect)
     {
          $percent = 48.0 / $height;
          $new_height = $height * $percent;
          $new_width = 11.875 * $new_height / 6.0 * $width / $height;
     }
     else
     {
          $percent = 164.0 / $width;
          $new_width = $width * $percent;
          $new_height = 6.0 * $new_width / 11.875 * $height / $width;
     }

     $image_p = imagecreatetruecolor($new_width, $new_height);
     imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

     for($i = 0; $i < $new_height; $i++)
     {
          $rgb = ImageColorAt($image_p, 0, $i);                              // OPTIMIZED
          $r = dechex(($rgb >> 16) & 0xFF);                              // OPTIMIZED
          $g = dechex(($rgb >> 8) & 0xFF);                              // OPTIMIZED
          $b = dechex($rgb & 0xFF);                                   // OPTIMIZED
          echo '<font color="#' . $r . $g . $b . '">' . strtoupper(dechex(rand(0, 15)));     // OPTIMIZED
          for($j = 1; $j < $new_width; $j++)
          {
               $rgb = ImageColorAt($image_p, $j, $i);
               $r = dechex(($rgb >> 16) & 0xFF);
               $g = dechex(($rgb >> 8) & 0xFF);
               $b = dechex($rgb & 0xFF);
               if(strlen($r) < 2)
               {
                    $r = '0' . $r;
               }
               if(strlen($g) < 2)
               {
                    $g = '0' . $g;
               }
               if(strlen($b) < 2)
               {
                    $b = '0' . $b;
               }
// NO OPTIMIZATION     echo '<font color="#' . $r . $g . $b . '">' . strtoupper(dechex(rand(0, 15))) . '</font>';
               if($rgb != ImageColorAt($image_p, $j - 1, $i))                    // OPTIMIZED
               {                                             // OPTIMIZED
                    echo '</font><font color="#' . $r . $g . $b . '">';          // OPTIMIZED
               }                                             // OPTIMIZED
               echo strtoupper(dechex(rand(0, 15)));                         // OPTIMIZED
          }                                                  // OPTIMIZED
          echo '</font>';                                             // OPTIMIZED
          echo '<br>' . "\n\n";
     }

     imagedestroy($image);
     imagedestroy($image_p);
?>
1 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject Adipex great buy.

    Tracked from Adipex no prescription. 2009/03/12 19:45 delete

    Generic adipex free consultation. Adipex that is shipped to missouri. Adipex fed ex.