Posts Tagged ‘数’
星期二, 06月 3rd, 2008
/// <summary>
/// 去除HTML标记
/// </summary>
/// <param name=”strHtml”>包括HTMLde源码 </param>
/// <returns>已经去除后de文字</returns>
public static string StripHTML(string strHtml)
{
string [] aryReg ={
@”<script[^>]*?>.*?</script>”,
@”<(\/\s*)?!?((\w :)?\w )(\w (\s*=?\s*(([""'])(\\[""'tbnr]|[^\7])*?\7|\w )|.{0})|\s)*?(\/\s*)?>”,
@”([\r\n])[\s] “,
@”&(quot|#34);”,
@”&(amp|#38);”,
@”&(lt|#60);”,
@”&(gt|#62);”,
@”&(nbsp|#160);”,
@”&(iexcl|#161);”,
@”&(cent|#162);”,
@”&(pound|#163);”,
@”&(copy|#169);”,
@”(\d );”,
@”–>”,
@”<!–.*\n”
};
string [] aryRep = {
“”,
“”,
“”,
“\”",
“&”,
“<”,
“>”,
” “,
“\xa1″,//chr(161),
“\xa2″,//chr(162),
“\xa3″,//chr(163),
“\xa9″,//chr(169),
“”,
“\r\n”,
“”
};
string newReg =aryReg[0];
string strOutput=strHtml;
for(int i = 0;i<aryReg.Length;i )
{
Regex regex = new Regex(aryReg[i],RegexOptions.IgnoreCase );
strOutput = regex.Replace(strOutput,aryRep[i]);
}
strOutput.Replace(”<”,”");
strOutput.Replace(”>”,”");
strOutput.Replace(”\r\n”,”");
return strOutput;
}
Tags: C函, HT, L代, ML, TM, 中文, 代码, 函数, 取H, 字的, 提取, 数, 文字, 的C, 码中
Posted in ASP.NET | No Comments »
星期二, 06月 3rd, 2008
给大家介绍几个.NET中Path类de几个方法:
1. Path.combine(string, string)
根据给出de两个路径, 返回一个路径.
例如:
string CompletePath = System.IO.Path.Combine(@”c:\MyApp”, @”Images\skyline.jpg”);
将会返回一个全路径 c:\MyApp\Images\skyline.jpg
第一个参数中有无”\”结尾都可以.
2. Path.GetExtension(string)
返回给定文件路径de扩展名.例如:
string FileExtention = System.IO.Path.GetExtention(@”C:\MyApp\Images\skyline.jpg”);
将会返回 “jpg”
3. Path.GetFileName(string)
给出文件名de全路径,返回文件名(包括扩展名).例如:
string fileName = System.IO.Path.GetFileName(@”c:\MyApp\Images\skyline.jpg”);
将会返回”skyline.jpg”
Tags: AS, ET, ne, PN, SP, t中, 个A, 中容, 介绍, 但却, 几个, 函数, 却很, 容易, 很重, 忽略, 数, 方法, 易忽, 法函, 略但, 的方, 绍几, 要的, 重要
Posted in ASP.NET | No Comments »
星期一, 06月 2nd, 2008
<html>
<meta http-equiv=”Refresh” content=”2″>
<!–
Place this code into an ASP Page and run it!
–>
<code>
Random FileName Creation
<%
Function Generator(Length)
dim i, tempS, v
dim c(39)
tempS = “”
c(1) = “a”: c(2) = “b”: c(3) = “c”: c(4) = “d”: c(5) = “e”: c(6) = “f”: c(7) = “g”
c(8) = “h”: c(9) = “i”: c(10) = “j”: c(11) = “k”: c(12) = “l”: c(13) = “m”: c(14) = “n”
c(15) = “o”: c(16) = “p”: c(17) = “q”: c(18) = “r”: c(19) = “s”: c(20) = “t”: c(21) = “u”
c(22) = “v”: c(23) = “w”: c(24) = “x”: c(25) = “y”: c(26) = “z”: c(27) = “1″: c(28) = “2″
c(29) = “3″: c(30) = “4″: c(31) = “5″: c(32) = “6″: c(33) = “7″: c(34) = “8″: c(35) = “9″
c(36) = “-”: c(37) = “_”: c(38) = “@”: c(39) = “!”
If isNumeric(Length) = False Then
Response.Write “A numeric datatype was not submitted to this function.”
Exit Function
End If
For i = 1 to Length
Randomize
v = Int((39 * Rnd) 1)
tempS = tempS & c(v)
Next
Generator = tempS
End Function
For i = 1 to 20
Randomize
x = Int((20 * Rnd) 1) 10
Response.Write Generator(x) & “<br>” & vbnewline
Next
%>
</code>
(出处:Viphot)
Tags: 件名, 函数, 名的, 成文, 数, 文件, 机生, 生成, 的函, 随机
Posted in JSP编程 | No Comments »
星期一, 06月 2nd, 2008
package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
/** Creates a table showing the current value of each
* of the standard CGI variables.
* <P>
* Taken from Core Servlets and JavaServer Pages
* from Prentice Hall and Sun Microsystems Press,
* http://www.coreservlets.com/.
* © 2000 Marty Hall; may be freely used or adapted.
*/
public class ShowCGIVariables extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String[][] variables =
{ { "AUTH_TYPE", request.getAuthType() },
{ "CONTENT_LENGTH",
String.valueOf(request.getContentLength()) },
{ "CONTENT_TYPE", request.getContentType() },
{ "DOCUMENT_ROOT",
getServletContext().getRealPath("/") },
{ "PATH_INFO", request.getPathInfo() },
{ "PATH_TRANSLATED", request.getPathTranslated() },
{ "QUERY_STRING", request.getQueryString() },
{ "REMOTE_ADDR", request.getRemoteAddr() },
{ "REMOTE_HOST", request.getRemoteHost() },
{ "REMOTE_USER", request.getRemoteUser() },
{ "REQUEST_METHOD", request.getMethod() },
{ "SCRIPT_NAME", request.getServletPath() },
{ "SERVER_NAME", request.getServerName() },
{ "SERVER_PORT",
String.valueOf(request.getServerPort()) },
{ "SERVER_PROTOCOL", request.getProtocol() },
{ "SERVER_SOFTWARE",
getServletContext().getServerInfo() }
};
String title = "Servlet Example: Showing CGI Variables";
out.println(ServletUtilities.headWithTitle(title)
"<BODY BGCOLOR=\"#FDF5E6\">\n"
"<H1 ALIGN=\"CENTER\">" title "</H1>\n"
"<TABLE BORDER=1 ALIGN=\"CENTER\">\n"
"<TR BGCOLOR=\"#FFAD00\">\n"
"<TH>CGI Variable Name<TH>Value");
for(int i=0; i<variables.length; i ) {
String varName = variables[i][0];
String varValue = variables[i][1];
if (varValue == null)
varValue = "<I>Not specified</I>";
out.println("<TR><TD>" varName "<TD>" varValue);
}
out.println("</TABLE></BODY></HTML>");
}
/** POST and GET requests handled identically. */
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
Tags: JS, p各, SP, 参数, 取j, 各种, 数, 种参, 获取
Posted in JSP编程 | No Comments »
星期一, 06月 2nd, 2008
一个可以删除字符串中HTML标记dePHP函数
作者:limote
当访客留言和发帖时,我并不希望访客在留言和帖子中使用HTML标记,所以在访客提交留言和帖子时我门得把HTML标记删除,下面de函数就是实现此功能de函数
<?
function delete_htm($scr)
{
for($i=0;$i<strlen($scr);$i )
{
if(substr($scr,$i,1)=="<")
{
while(substr($scr,$i,1)!=">")$i ;
$i ;
}
$str=$str.substr($scr,$i,1);
}
return($str);
}
?>
Tags: 一个, 个可, 中H, 串中, 以删, 函数, 删除, 可以, 字符, 数, 标记, 的P, 符串, 记的, 除字, hp, HT, L标, ML, P函, ph, TM
Posted in PHP编程 | No Comments »
星期一, 06月 2nd, 2008
尽管PHP为我提供了很多函数,但有些东西处理起来还是不很方便.譬如PHP提供de日期时间函数就很有限.Mysql为我提供了不少此类de函数.是否可以利用Mysql函数来处理PHP程序呢?笔者做了以下de尝试.
<?php
$data_time="1998-12-31 23:59:59";
$connect_id=mysql_connect(’localhost’);
$query_id=mysql_query("SELECT DATE_ADD(’$data_time’,INTERVAL 1 YEAR)",$connect_id);
$data_time=mysql_result($query_id,0);
mysql_close($connect_id);
echo $data_time;
?>
举一反三,我在编程过程中还可以利用Mysql提供de其他函数.
当然Mysql提供de函数及其用法就拜托大家去查手册了.
不当之处敬请指正!
作者Email:fancao0515@0451.com
fancao0515@21cn.com
【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】
Tags: HP, L函, my, PH, p编, QL, SQ, ys, ——, —利, 之高, 函数, 利用, 巧—, 技巧, 数, 用M, 程之, 级技, 编程, 高级
Posted in PHP编程 | No Comments »
星期一, 06月 2nd, 2008
函数名称:array_multi2single
函数原形:array array_multi2single(array)
实现功能:把一个多维数组de数值存放到一维数组中,不保存Key.
<?php
function array_multi2single($array)
{
static $result_array=array();
foreach($array as $value)
{
if(is_array($value))
{
array_multi2single($value);
}
else
$result_array[]=$value;
}
return $result_array;
}
//函数测试部分
$array=array("1"=>array("A","B","C",array("D","E")),"2"=>array("F","G","H","I"));
$array=array_multi2single($array);
echo "<h1>测试结果:</h1>";
foreach($array as $value)
{
echo "<h5>$value</h5>";
echo "<br>";
}
?>
欢迎大家批评指正!
作者Email:fancao0515@0451.com
【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】
Tags: 一维, 为一, 函数, 利用, 多维, 归把, 把多, 数, 数组, 用递, 的函, 组的, 组转, 维数, 转为, 递归
Posted in PHP编程 | No Comments »
星期一, 06月 2nd, 2008
在C/C 中,头文件ctype.h中定义了关于字符类型一组宏,可以得到给定字符de类型.
而PHP中没有相关函数.前些天发现在www.mm4.de下载dePHP中提供了一个名为php_ctype.dllde扩展库,
加载后发现提供一部分此类de函数,特整理出来供大家参考.
在PHP中正确加载php_ctype.dll文件后,用<?php phpinfo();?>可以看到以下信息:
ctype
ctype functions enabled (experimental)
然后就可以使用它所提供de函数了.所有函数de用法同C/C 基本相同,区别在于在C/C 中函数de参数是
字符型(char),而在PHP中函数de参数可以是字符串(string).例如:
<?php
$string="123ADAADAD";
if(isalnum($string))
{
echo "只有大小写字母和数字!";
}
?>
附:php_ctype.dll支持de函数
bool isalnum(string)
bool isalpha(string)
bool iscntrl(string)
bool isdigit(string)
bool isgraph(string)
bool islower(string)
bool isprint(string)
bool ispunct(string)
bool isspace(string)
bool isupper(string)
bool isxdigit(string)
【本文版权归作者凡草0515与奥索网共同拥有,如需转载,请注明作者及出处】
Tags: cc, C迁, HP, PH, P—, ——, —判, 从C, 函数, 判断, 到P, 型的, 字符, 数, 断字, 的函, 移到, 符类, 类型, 迁移
Posted in PHP编程 | No Comments »
星期一, 06月 2nd, 2008
// php 中 一个控制字符串输出de函数(中英文),每行显示多少字数,避免英文de影响
// $str 字符串
// $len 每行显示de字数(汉字×2)
function rep($str,$len)
{
$strlen=strlen($str);
$i=0;
$finstr="";
$pos=0;
while($i<$strlen)
{
$s1=substr($str,$i,1);
$s2=ord($s1);
if($s2>0xa0){
$finstr.=substr($str,$i,2);
$pos =2;
$i =2;
}else{
switch($s2){
case 13:
$finstr.="<BR>";
$pos=0;
break;
case 10:
$pos=0;
break;
case 32;
$finstr.=" ";
$pos ;
break;
default:
$finstr.=htmlspecialchars($s1);
$pos ;
break;
}
$i ;
} //if
if($pos>=$len){
$finstr.="<BR>";
$pos=0;
}
} //while
return $finstr;
}
Tags: HP, PH, P中, 一个, 个控, 中一, 串输, 出的, 函数, 制字, 字符, 控制, 数, 的函, 符串, 输出
Posted in PHP编程 | No Comments »
星期一, 06月 2nd, 2008
一个取得文件扩展名de函数
<?
/*
GetFileType
用法:GetFiletype($filename)
*/
function GetFiletype($Filename) {
if (substr_count($Filename, ".") == 0) { // 检查文件名中是否有.号.
return; // 返回空
} else if (substr($Filename, -1) == ".") { // 检查是否以.结尾,即无扩展名
return; // 返回空
} else {
$FileType = strrchr ($Filename, "."); // 从.号处切割
$FileType = substr($FileType, 1); // 去除.号
return $FileType; // 返回
}
}
$Filename = "Testfilename.php4";
$Filename = GetFileType($Filename);
echo $Filename; // 打印出php4
Tags: 一个, 个取, 件扩, 函数, 取得, 名的, 展名, 得文, 扩展, 数, 文件, 的函
Posted in PHP编程 | No Comments »