June 2008


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<TITLE>Text word and character counter</TITLE>
<meta name="description" content="Use this handy tool to get a count of the words or characters in a text document.">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Shawn Seley -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function CountWords (this_field, show_word_count, show_char_count) {
if (show_word_count == null) {
show_word_count = true;
}
if (show_char_count == null) {
show_char_count = false;
}
var char_count = this_field.value.length;
var fullStr = this_field.value + " ";
var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
var splitString = cleanedStr.split(" ");
var word_count = splitString.length -1;
if (fullStr.length <2) {
word_count = 0;
}
if (word_count == 1) {
wordOrWords = " word";
}
else {
wordOrWords = " words";
}
if (char_count == 1) {
charOrChars = " character";
} else {
charOrChars = " characters";
}
if (show_word_count & show_char_count) {
alert ("Word Count:\n" + "    " + word_count + wordOrWords + "\n" + "    " + char_count + charOrChars);
}
else {
if (show_word_count) {
alert ("Word Count:  " + word_count + wordOrWords);
}
else {
if (show_char_count) {
alert ("Character Count:  " + char_count + charOrChars);
      }
   }
}
return word_count;
}
//  End -->
</script>
</head>

<body>
<table width="62%" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr align="left" valign="top">
          <td with="472" width="472"><h1 align="center" class="pad10"><font size="2" face="Arial, Helvetica, sans-serif">
          Word and Character Counter</font></h1>
          <p align="center" ><font size="2" face="Arial, Helvetica, sans-serif">
          Use this handy tool to get a count of the words or characters in a
          text document. It's useful for word counts for article submissions,
          word or character counts for advertising copy, or any time you need to
          know how many words or characters your text contains.</font></p>
          <p align="center" class="pad10"><font size="2" face="Arial, Helvetica, sans-serif">
          NOTE: In order to use the tool your browser must have JavaScript
          installed and enabled.</font></p>
          <div class="pad10">


<hr>

<p align="center"><font size="2" face="Arial, Helvetica, sans-serif">
          Type or paste your text into the form below and click the button to
          get a word and character count.</font></p>
            </div>

                  <div>
                    <form>
            <div align="center"><font face="Arial, Helvetica, sans-serif">
  <textarea cols=40 rows=10 name=x>
  </textarea>
  <br>
  <input type=button value="Count Words and Characters" OnClick ="CountWords(this.form.x, true, true);">
            </font></div>
                  </form>

<p align="center">
<p align="center">&nbsp;</p>
                  </div>
                  </td>
  </tr>
</table>
</body>
</html>

Note: I did not write this script. I just found it on the web. I’m just sharing the script. I used it once on my page.

Thank you.

<?php

// define the base image dir
$base_img_dir = "./";

// $QUERY_STRING =
//  f(3c9b5fa6bc0fa)  img_file
//  w(123|15%)        width of output
//  h(123|10%)        height of output
//  x(123)            max width of output
//  y(123)            max height of output
//  t(jpg|png)        type of output
//  q(100)            quality of jpeg

// find tags
preg_match_all("/\+*(([a-z])\(([^\)]+)\))\+*/", $QUERY_STRING,
                $matches, PREG_SET_ORDER);

// empty array and set regular expressions for the check
$tags = array();
$check = array( "f" => "[0-9a-zA-Z]{13}",
                "w" => "[0-9]+%?",
                "h" => "[0-9]+%?",
                "x" => "[0-9]+",
                "y" => "[0-9]+",
                "t" => "jpg|png",
                "q" => "1?[0-9]{1,2}" );

// check tags and save correct values in array
for ($i=0; $i<count($matches); $i++) {
    if (isset($check[$matches[$i][2]])) {
        if (preg_match('/^('.$check[$matches[$i][2]].')$/',
               $matches[$i][3])) {
            $tags[$matches[$i][2]] = $matches[$i][3];
        }
    }
}

function notfound() {
    header("HTTP/1.0 404 Not Found");
    exit;
}

// check that filename is given
if (!isset($tags["f"])) {
    notfound();
}

// check if file exists
if (!file_exists($base_img_dir.$tags["f"])) {
    notfound();
}

// retrieve file info
$imginfo = getimagesize($base_img_dir.$tags["f"]);

// load image
switch ($imginfo[2]) {
    case 2:     // jpg
        $img_in = imagecreatefromjpeg($base_img_dir.$tags["f"]) or notfound();
        if (!isset($tags["t"])) {
            $tags["t"] = "jpg";
        }
        break;
    case 3:     // png
        $img_in = imagecreatefrompng($base_img_dir.$tags["f"]) or notfound();
        if (!isset($tags["t"])) {
            $tags["t"] = "png";
        }
        break;
    default:
        notfound();
}

// check for maximum width and height
if (isset($tags["x"])) {
    if ($tags["x"] < imagesx($img_in)) {
        $tags["w"] = $tags["x"];
    }
}
if (isset($tags["y"])) {
    if ($tags["y"] < imagesy($img_in)) {
        $tags["h"] = $tags["y"];
    }
}

// check for need to resize
if (isset($tags["h"]) or isset($tags["w"])) {
    // convert relative to absolute
    if (isset($tags["w"])) {
        if (strstr($tags["w"], "%")) {
            $tags["w"] = (intval(substr($tags["w"], 0, -1)) / 100) *
                          $imginfo[0];
        }
    }
    if (isset($tags["h"])) {
        if (strstr($tags["h"], "%")) {
            $tags["h"] = (intval(substr($tags["h"], 0, -1)) / 100) *
                          $imginfo[1];
        }
    }

    // resize
    if (isset($tags["w"]) and isset($tags["h"])) {
        $out_w = $tags["w"];
        $out_h = $tags["h"];
    } elseif (isset($tags["w"]) and !isset($tags["h"])) {
        $out_w = $tags["w"];
        $out_h = $imginfo[1] * ($tags["w"] / $imginfo[0]);
    } elseif (!isset($tags["w"]) and isset($tags["h"])) {
        $out_w = $imginfo[0] * ($tags["h"] / $imginfo[1]);
        $out_h = $tags["h"];
    } else {
        $out_w = $tags["w"];
        $out_h = $tags["h"];
    }
   
    // new image in $img_out
    $img_out = imagecreate($out_w, $out_h);
    imagecopyresized($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out),
               imagesy($img_out), imagesx($img_in), imagesy($img_in));
} else {
    // no resize needed
    $img_out = $img_in;
}

// check for a given jpeg-quality, otherwise set to default
if (!isset($tags["q"])) {
    $tags["q"] = 75;
}

// returning the image
switch ($tags["t"]) {
    case "jpg":
        header("Content-type: image/jpeg");
        imagejpeg($img_out, "", $tags["q"]);
        exit;
    case "png":
        header("Content-type: image/png");
        imagepng($img_out);
        exit;
   default:
        notfound();
}

?>

Note: I did not write this script. I just found it on the web. I’m just sharing the script. I used it once on my page.

Thank you.