当前位置: 编程技术>php
本页文章导读:
▪将RTF格式的文件转成HTML并在网页中显示的代码
将RTF格式的文件转成HTML并在网页中显示的代码 它是这样工作的,将一个RTF文件上传,然后转成HTML显示出来,代码有点复杂,teaman还要好好研究,好象中文版有点问题。 <html> &.........
▪简单的用PHP编写的导航条程序
//简单的用PHP编写的导航条程序 <?php //导航条配置说明:默认显示的是目录名 //如果不愿意使用目录名,请去掉下面一行注释,并修改数组元素 $label= array("目录1"=>"导航名1","目录2"=>.........
▪信用卡效验程序
<?php //////////////////////////////////////////////////// // // // Credit card validation routine // //.........
[1]将RTF格式的文件转成HTML并在网页中显示的代码
来源: 互联网 发布时间: 2013-11-30
将RTF格式的文件转成HTML并在网页中显示的代码
它是这样工作的,将一个RTF文件上传,然后转成HTML显示出来,代码有点复杂,teaman还要好好研究,好象中文版有点问题。
<html>
<body>
<?
if(!($userfile)) {
?>
<form enctype="multipart/form-data" action="/blog_article/</print($PHP_SELF);/gt;.html" method=post>
<input type=hidden name="max_file_size" value=2000>
Send this file: <input name=userfile type=file>
<input type=submit value=Upload>
</form>
</body>
</html>
<?
exit;
}
function ProcessTags($tags, $line) {
$html = "";
global $color;
global $size;
global $bullets;
// Remove spaces.
$tags = trim($tags);
// Found the beginning of the bulleted l
// ist.
if(ereg("\\\pnindent", $tags)) {
$html .= "<ul><li>";
$bullets += $line;
$tags = ereg_replace("\\\par", "", $tags);
$tags = ereg_replace("\\\(tab)", "", $tags);
}
if($line - $bullets == 0) {
$tags = ereg_replace("\\\par", "", $tags);
}
elseif($line - $bullets == 1) {
if(ereg("\\\pntext", $tags)) {
$html .= "<li>";
$tags = ereg_replace("\\\par", "", $tags);
$tags = ereg_replace("\\\(tab)", "", $tags);
$bullets++;
}
else {
$html .= "</ul>";
$bullets = 0;
}
}
// Convert Bold.
if(ereg("\\\b0", $tags)){ $html .= "</b>"; }
elseif(ereg("\\\b", $tags)) { $html .= "<b>"; }
// Convert Italic.
if(ereg("\\\i0", $tags)){ $html .= "</i>"; }
elseif(ereg("\\\i", $tags)) { $html .= "<i>"; }
// Convert Underline.
if(ereg("\\\ulnone", $tags)){ $html .= "</u>"; }
elseif(ereg("\\\ul", $tags)){ $html .= "<u>"; }
// Convert Alignments.
if(ereg("\\\pard\\\qc", $tags)) { $html .= "<div align=center>"; }
elseif(ereg("\\\pard\\\qr", $tags)) { $html .= "<div align=right>"; }
elseif(ereg("\\\pard", $tags)){ $html .= "<div align=left>"; }
// Remove \pard from the tags so it does
// n't get confused with \par.
$tags = ereg_replace("\\\pard", "", $tags);
// Convert line breaks.
if(ereg("\\\par", $tags)){ $html .= "<br>"; }
// Use the color table to capture the fo
// nt color changes.
if(ereg("\\\cf[0-9]", $tags)) {
global $fcolor;
$numcolors = count($fcolor);
for($i = 0; $i < $numcolors; $i++) {
$test = "\\\cf" . ($i + 1);
if(ereg($test, $tags)) {
$color = $fcolor[$i];
}
}
}
// Capture font size changes.
if(ereg("\\\fs[0-9][0-9]", $tags, $temp)) {
$size = ereg_replace("\\\fs", "", $temp[0]);
$size /= 2;
if($size <= 10) { $size = 1; }
elseif($size <= 12) { $size = 2; }
elseif($size <= 14) { $size = 3; }
elseif($size <= 16) { $size = 4; }
elseif($size <= 18) { $size = 5; }
elseif($size <= 20) { $size = 6; }
elseif($size <= 22) { $size = 7; }
else{ $size = 8; }
}
// If there was a font color or size cha
// nge, change the font tag now.
if(ereg("(\\\cf[0-9])||(\\\fs[0-9][0-9])", $tags)) {
$html .= "</font><font size=$size color=$color>";
}
// Replace \tab with alternating spaces
// and nonbreakingwhitespaces.
if(ereg("\\\(tab)", $tags)) { $html .= " "; }
return $html;
}
function ProcessWord($word) {
// Replace \\ with \
$word = ereg_replace("[\\]{2,}", "\\", $word);
// Replace \{ with {
$word = ereg_replace("[\\][\{]", "\{", $word);
// Replace \} with }
$word = ereg_replace("[\\][\}]", "\}", $word);
// Replace 2 spaces with one space.
$word = ereg_replace(" ", " ", $word);
return $word;
}
$color = "000000";
$size = 1;
$bullets = 0;
// Read the uploaded file into an array.
//
$rtfile = file($userfile);
$fileLength = count($rtfile);
// Loop through the rest of the array
for($i = 1; $i < $fileLength; $i++) {
/*
** If the line contains "\colortbl" then we found the color table.
** We'll have to split it up into each individual red, green, and blue
** Convert it to hex and then put the red, green, and blue back together.
** Then store each into an array called fcolor.
*/
if(ereg("^\{\\\colortbl", $rtfile[$i])) {
// Split the line by the backslash.
$colors = explode("\\", $rtfile[$i]);
$numOfColors = count($colors);
for($k = 2; $k < $numOfColors; $k++) {
// Find out how many different colors th
// ere are.
if(ereg("[0-9]+", $colors[$k], $matches)) {
$match[] = $matches[0];
}
}
// For each color, convert it to hex.
$numOfColors = count($match);
for($k = 0; $k < $numOfColors; $k += 3) {
$red = dechex($match[$k]);
$red = $match[$k] < 16 ? "0$red" : $red;
$green = dechex($match[$k + 1]);
$green = $match[$k +1] < 16 ? "0$green" : $green;
$blue = dechex($match[$k + 2]);
$blue = $match[$k + 2] < 16 ? "0$blue" : $blue;
$fcolor[] = "$red$green$blue";
}
$numOfColors = count($fcolor);
}
// Or else, we parse the line, pulling o
// ff words and tags.
else {
$token = "";
$start = 0;
$lineLength = strlen($rtfile[$i]);
for($k = 0; $k < $lineLength; $k++) {
if($rtfile[$i][$start] == "\\" && $rtfile[$i][$start + 1] != "\\") {
// We are now dealing with a tag.
$token .= $rtfile[$i][$k];
if($rtfile[$i][$k] == " ") {
$newFile[$i] .= ProcessTags($token, $i);
$token = "";
$start = $k + 1;
}
elseif($rtfile[$i][$k] == "\n") {
$newFile[$i] .= ProcessTags($token, $i);
$token = "";
}
}
elseif($rtfile[$i][$start] == "{") {
// We are now dealing with a tag.
$token .= $rtfile[$i][$k];
if($rtfile[$i][$k] == "}") {
$newFile[$i] .= ProcessTags($token, $i);
$token = "";
$start = $k + 1;
}
}
else {
// We are now dealing with a word.
if($rtfile[$i][$k] == "\\" && $rtfile[$i][$k + 1] != "\\" && $rtfile[$i][$k - 1] != "\\") {
$newFile[$i] .= ProcessWord($token);
$token = $rtfile[$i][$k];
$start = $k;
}
else {
$token .= $rtfile[$i][$k];
}
}
}
}
}
$limit = sizeof($newFile);
for($i = 0; $i < $limit; $i++) {
print("$newFile[$i]\n");
}
?>
</body>
</html>
它是这样工作的,将一个RTF文件上传,然后转成HTML显示出来,代码有点复杂,teaman还要好好研究,好象中文版有点问题。
<html>
<body>
<?
if(!($userfile)) {
?>
<form enctype="multipart/form-data" action="/blog_article/</print($PHP_SELF);/gt;.html" method=post>
<input type=hidden name="max_file_size" value=2000>
Send this file: <input name=userfile type=file>
<input type=submit value=Upload>
</form>
</body>
</html>
<?
exit;
}
function ProcessTags($tags, $line) {
$html = "";
global $color;
global $size;
global $bullets;
// Remove spaces.
$tags = trim($tags);
// Found the beginning of the bulleted l
// ist.
if(ereg("\\\pnindent", $tags)) {
$html .= "<ul><li>";
$bullets += $line;
$tags = ereg_replace("\\\par", "", $tags);
$tags = ereg_replace("\\\(tab)", "", $tags);
}
if($line - $bullets == 0) {
$tags = ereg_replace("\\\par", "", $tags);
}
elseif($line - $bullets == 1) {
if(ereg("\\\pntext", $tags)) {
$html .= "<li>";
$tags = ereg_replace("\\\par", "", $tags);
$tags = ereg_replace("\\\(tab)", "", $tags);
$bullets++;
}
else {
$html .= "</ul>";
$bullets = 0;
}
}
// Convert Bold.
if(ereg("\\\b0", $tags)){ $html .= "</b>"; }
elseif(ereg("\\\b", $tags)) { $html .= "<b>"; }
// Convert Italic.
if(ereg("\\\i0", $tags)){ $html .= "</i>"; }
elseif(ereg("\\\i", $tags)) { $html .= "<i>"; }
// Convert Underline.
if(ereg("\\\ulnone", $tags)){ $html .= "</u>"; }
elseif(ereg("\\\ul", $tags)){ $html .= "<u>"; }
// Convert Alignments.
if(ereg("\\\pard\\\qc", $tags)) { $html .= "<div align=center>"; }
elseif(ereg("\\\pard\\\qr", $tags)) { $html .= "<div align=right>"; }
elseif(ereg("\\\pard", $tags)){ $html .= "<div align=left>"; }
// Remove \pard from the tags so it does
// n't get confused with \par.
$tags = ereg_replace("\\\pard", "", $tags);
// Convert line breaks.
if(ereg("\\\par", $tags)){ $html .= "<br>"; }
// Use the color table to capture the fo
// nt color changes.
if(ereg("\\\cf[0-9]", $tags)) {
global $fcolor;
$numcolors = count($fcolor);
for($i = 0; $i < $numcolors; $i++) {
$test = "\\\cf" . ($i + 1);
if(ereg($test, $tags)) {
$color = $fcolor[$i];
}
}
}
// Capture font size changes.
if(ereg("\\\fs[0-9][0-9]", $tags, $temp)) {
$size = ereg_replace("\\\fs", "", $temp[0]);
$size /= 2;
if($size <= 10) { $size = 1; }
elseif($size <= 12) { $size = 2; }
elseif($size <= 14) { $size = 3; }
elseif($size <= 16) { $size = 4; }
elseif($size <= 18) { $size = 5; }
elseif($size <= 20) { $size = 6; }
elseif($size <= 22) { $size = 7; }
else{ $size = 8; }
}
// If there was a font color or size cha
// nge, change the font tag now.
if(ereg("(\\\cf[0-9])||(\\\fs[0-9][0-9])", $tags)) {
$html .= "</font><font size=$size color=$color>";
}
// Replace \tab with alternating spaces
// and nonbreakingwhitespaces.
if(ereg("\\\(tab)", $tags)) { $html .= " "; }
return $html;
}
function ProcessWord($word) {
// Replace \\ with \
$word = ereg_replace("[\\]{2,}", "\\", $word);
// Replace \{ with {
$word = ereg_replace("[\\][\{]", "\{", $word);
// Replace \} with }
$word = ereg_replace("[\\][\}]", "\}", $word);
// Replace 2 spaces with one space.
$word = ereg_replace(" ", " ", $word);
return $word;
}
$color = "000000";
$size = 1;
$bullets = 0;
// Read the uploaded file into an array.
//
$rtfile = file($userfile);
$fileLength = count($rtfile);
// Loop through the rest of the array
for($i = 1; $i < $fileLength; $i++) {
/*
** If the line contains "\colortbl" then we found the color table.
** We'll have to split it up into each individual red, green, and blue
** Convert it to hex and then put the red, green, and blue back together.
** Then store each into an array called fcolor.
*/
if(ereg("^\{\\\colortbl", $rtfile[$i])) {
// Split the line by the backslash.
$colors = explode("\\", $rtfile[$i]);
$numOfColors = count($colors);
for($k = 2; $k < $numOfColors; $k++) {
// Find out how many different colors th
// ere are.
if(ereg("[0-9]+", $colors[$k], $matches)) {
$match[] = $matches[0];
}
}
// For each color, convert it to hex.
$numOfColors = count($match);
for($k = 0; $k < $numOfColors; $k += 3) {
$red = dechex($match[$k]);
$red = $match[$k] < 16 ? "0$red" : $red;
$green = dechex($match[$k + 1]);
$green = $match[$k +1] < 16 ? "0$green" : $green;
$blue = dechex($match[$k + 2]);
$blue = $match[$k + 2] < 16 ? "0$blue" : $blue;
$fcolor[] = "$red$green$blue";
}
$numOfColors = count($fcolor);
}
// Or else, we parse the line, pulling o
// ff words and tags.
else {
$token = "";
$start = 0;
$lineLength = strlen($rtfile[$i]);
for($k = 0; $k < $lineLength; $k++) {
if($rtfile[$i][$start] == "\\" && $rtfile[$i][$start + 1] != "\\") {
// We are now dealing with a tag.
$token .= $rtfile[$i][$k];
if($rtfile[$i][$k] == " ") {
$newFile[$i] .= ProcessTags($token, $i);
$token = "";
$start = $k + 1;
}
elseif($rtfile[$i][$k] == "\n") {
$newFile[$i] .= ProcessTags($token, $i);
$token = "";
}
}
elseif($rtfile[$i][$start] == "{") {
// We are now dealing with a tag.
$token .= $rtfile[$i][$k];
if($rtfile[$i][$k] == "}") {
$newFile[$i] .= ProcessTags($token, $i);
$token = "";
$start = $k + 1;
}
}
else {
// We are now dealing with a word.
if($rtfile[$i][$k] == "\\" && $rtfile[$i][$k + 1] != "\\" && $rtfile[$i][$k - 1] != "\\") {
$newFile[$i] .= ProcessWord($token);
$token = $rtfile[$i][$k];
$start = $k;
}
else {
$token .= $rtfile[$i][$k];
}
}
}
}
}
$limit = sizeof($newFile);
for($i = 0; $i < $limit; $i++) {
print("$newFile[$i]\n");
}
?>
</body>
</html>
[2]简单的用PHP编写的导航条程序
来源: 互联网 发布时间: 2013-11-30
//简单的用PHP编写的导航条程序
<?php
//导航条配置说明:默认显示的是目录名
//如果不愿意使用目录名,请去掉下面一行注释,并修改数组元素
$label=
array("目录1"=>"导航名1","目录2"=>"导航名2","目录3"=>"导航名3");
$ur1=$REQUEST_URI;
while($ur1 != ""){
$text=basename($ur1);
//获取文件名
if(isset($label[$text]))
{$text=$label[$text]; }
$link=$ur1;
$curx= " > <a href="/blog_article/$link/index.html">$text</a>";
$komplettx= $curx.$komplettx;
$ur1=dirname($ur1);
//获取目录名
}
echo $komplettx;
?>
//在页面中可以用include调用该程序
<?php
//导航条配置说明:默认显示的是目录名
//如果不愿意使用目录名,请去掉下面一行注释,并修改数组元素
$label=
array("目录1"=>"导航名1","目录2"=>"导航名2","目录3"=>"导航名3");
$ur1=$REQUEST_URI;
while($ur1 != ""){
$text=basename($ur1);
//获取文件名
if(isset($label[$text]))
{$text=$label[$text]; }
$link=$ur1;
$curx= " > <a href="/blog_article/$link/index.html">$text</a>";
$komplettx= $curx.$komplettx;
$ur1=dirname($ur1);
//获取目录名
}
echo $komplettx;
?>
//在页面中可以用include调用该程序
[3]信用卡效验程序
来源: 互联网 发布时间: 2013-11-30
<?php
////////////////////////////////////////////////////
// //
// Credit card validation routine //
// May 15, 2000 //
// By ariso //
// validateCardCode($number[,$cardtype]) //
////////////////////////////////////////////////////
function validateCardCode($cardnumber, $cardtype = 'unknown')
{
//Clean up input
$cardtype = strtolower($cardtype);
$cardnumber = ereg_replace( '[-[:space:]]', '',$cardnumber);
//Do type specific checks
if ($cardtype == 'unknown') {
//Skip type specific checks
}
elseif ($cardtype == 'mastercard'){
if (strlen($cardnumber) != 16 || !ereg( '5[1-5]', $cardnumber)) return 0;
}
elseif ($cardtype == 'visa'){
if ((strlen($cardnumber) != 13 && strlen($cardnumber) != 16) || substr($cardnumber, 0, 1) != '4')
return 0;
}
elseif ($cardtype == 'amex'){
if (strlen($cardnumber) != 15 || !ereg( '3[47]', $cardnumber)) return a;
}
elseif ($cardtype == 'discover'){
if (strlen($cardnumber) != 16 || substr($cardnumber, 0, 4) != '6011') return 0;
}
else {
//invalid type entered
return -1;
}
// Start MOD 10 checks
$dig = toCharArray($cardnumber);
$numdig = sizeof ($dig);
$intIntJ = 0;
for ($intI=($numdig-2); $intI>=0; $intI-=2){
$dbl[$intIntJ] = $dig[$intI] * 2;
$intIntJ++;
}
$dblsz = sizeof($dbl);
$validate =0;
for ($intI=0;$intI<$dblsz;$intI++){
$add = toCharArray($dbl[$intI]);
for ($intIntJ=0;$intIntJ<sizeof($add);$intIntJ++){
$validate += $add[$intIntJ];
}
$add = '';
}
for ($intI=($numdig-1); $intI>=0; $intI-=2){
$validate += $dig[$intI];
}
if (substr($validate, -1, 1) == '0') return 1;
else return 0;
}
// takes a string and returns an array of characters
function toCharArray($intInput){
$len = strlen($intInput);
for ($intIntJ=0;$intIntJ<$len;$intIntJ++){
$char[$intIntJ] = substr($intInput, $intIntJ, 1);
}
return ($char);
}
?>
////////////////////////////////////////////////////
// //
// Credit card validation routine //
// May 15, 2000 //
// By ariso //
// validateCardCode($number[,$cardtype]) //
////////////////////////////////////////////////////
function validateCardCode($cardnumber, $cardtype = 'unknown')
{
//Clean up input
$cardtype = strtolower($cardtype);
$cardnumber = ereg_replace( '[-[:space:]]', '',$cardnumber);
//Do type specific checks
if ($cardtype == 'unknown') {
//Skip type specific checks
}
elseif ($cardtype == 'mastercard'){
if (strlen($cardnumber) != 16 || !ereg( '5[1-5]', $cardnumber)) return 0;
}
elseif ($cardtype == 'visa'){
if ((strlen($cardnumber) != 13 && strlen($cardnumber) != 16) || substr($cardnumber, 0, 1) != '4')
return 0;
}
elseif ($cardtype == 'amex'){
if (strlen($cardnumber) != 15 || !ereg( '3[47]', $cardnumber)) return a;
}
elseif ($cardtype == 'discover'){
if (strlen($cardnumber) != 16 || substr($cardnumber, 0, 4) != '6011') return 0;
}
else {
//invalid type entered
return -1;
}
// Start MOD 10 checks
$dig = toCharArray($cardnumber);
$numdig = sizeof ($dig);
$intIntJ = 0;
for ($intI=($numdig-2); $intI>=0; $intI-=2){
$dbl[$intIntJ] = $dig[$intI] * 2;
$intIntJ++;
}
$dblsz = sizeof($dbl);
$validate =0;
for ($intI=0;$intI<$dblsz;$intI++){
$add = toCharArray($dbl[$intI]);
for ($intIntJ=0;$intIntJ<sizeof($add);$intIntJ++){
$validate += $add[$intIntJ];
}
$add = '';
}
for ($intI=($numdig-1); $intI>=0; $intI-=2){
$validate += $dig[$intI];
}
if (substr($validate, -1, 1) == '0') return 1;
else return 0;
}
// takes a string and returns an array of characters
function toCharArray($intInput){
$len = strlen($intInput);
for ($intIntJ=0;$intIntJ<$len;$intIntJ++){
$char[$intIntJ] = substr($intInput, $intIntJ, 1);
}
return ($char);
}
?>
最新技术文章: