5贪婪模式:
前面在元字符中提到过"?"还有一个重要的作用,即"贪婪模式",什么是"贪婪模式"呢?
比如我们要匹配以字母"a"开头字母"b"结尾的字符串,但是需要匹配的字符串在"a"后面含有很多个"b",比如"a bbbbbbbbbbbbbbbbb",那正则表达式是会匹配第一个"b"还是最后一个"b"呢?如果你使用了贪婪模式,那么会匹配到最后一个"b",反之只是匹配到第一个"b"。
使用贪婪模式的表达式如下:
/a.+?b/
/a.+b/U
不使用贪婪模式的如下:
/a.+b/
上面使用了一个修饰符U,详见下面的部分。
修饰符:
在正则表达式里面的修饰符可以改变正则的很多特性,使得正则表达式更加适合你的需要(注意:修饰符对于大小写是敏感的,这意味着"e"并不等于"E")。正则表达式里面的修饰符如下:
i :如果在修饰符中加上"i",则正则将会取消大小写敏感性,即"a"和"A" 是一样的。
m:默认的正则开始"^"和结束"$"只是对于正则字符串如果在修饰符中加上"m",那么开始和结束将会指字符串的每一行:每一行的开头就是"^",结尾就是"$"。
s:如果在修饰符中加入"s",那么默认的"."代表除了换行符以外的任何字符将会变成任意字符,也就是包括换行符!
x:如果加上该修饰符,表达式中的空白字符将会被忽略,除非它已经被转义。
e:本修饰符仅仅对于replacement有用,代表在replacement中作为PHP代码。
A:如果使用这个修饰符,那么表达式必须是匹配的字符串中的开头部分。比如说"/a/A"匹配"abcd"。
E:与"m"相反,如果使用这个修饰符,那么"$"将匹配绝对字符串的结尾,而不是换行符前面,默认就打开了这个模式。
U:和问号的作用差不多,用于设置"贪婪模式"。
从数据库里取N个字段,然后组合到一起用“,”分割显示,起初想到用CONCAT()来处理,好是麻烦,没想到在手册里居然有提到CONCAT_WS(),非常好用。
CONCAT_WS(separator, str1, str2,...)
它是一个特殊形式的 CONCAT()。第一个参数剩余参数间的分隔符。分隔符可以是与剩余参数一样的字符串。如果分隔符是 NULL,返回值也将为 NULL。这个函数会跳过分隔符参数后的任何 NULL 和空字符串。分隔符将被加到被连接的字符串之间
简单例子如下:
mysql> SELECT CONCAT_WS(",","First name","Second name","Last Name");
-> 'First name,Second name,Last Name'
mysql> SELECT CONCAT_WS(",","First name",NULL,"Last Name");
-> 'First name,Last Name'
摘要: 我们经常将Excel格式的文件保存为csv格式以方便上传和修改,可是当数据中包含逗号和双引号的时候Excel会把该字段用双引号括住并把数据中的"改为"",usingSystem;/**//***TheCommaSeparatedValue(CSV)FileFormat:http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm*描述:解析CSV格式的文...
阅读全文
刚刚一段代码由于考虑用户体验要用js实现,但要传隐秘信息到服务器验证,找到该函数,测试成功,不支持中文, 但对通常的密码加密已足够
使用方法
<script type="text/javascript" src="md5.js"></script>
<script type="text/javascript" >
hash = hex_md5("input string");
</script>
官方网站:http://pajhome.org.uk/crypt/md5/
个人认为的好处:
1、减少服务器在md5加密的负担
2、这样传输过程的安全也得到加强,使用JS可以得到更好的客户体验
md5.js下载
sha-1.js下载
Introduction
At Atalasoft, we’re excited to unveil the newest addition to our product line, Atalasoft OCR. This suite of objects, now available, provides interfacing to OCR engines in a way that makes integration into your .NET application a snap.
In the classes provided, we offer the best of all possible worlds: a multilayered approach to exposing engine capabilities that gets up and running quickly, yet also allows you to get down to the nitty gritty details that are most important to you.
When using Atalasoft OCR engine in its most basic way, most of the work is in managing the user interface and not the OCR engine.
The following snippet of C# code demonstrates how to convert a set of image files into a single plain text file.
static void Main(string[] args)


{
// create and initialize the engine
ExperVisionEngine engine = new ExperVisionEngine(null, null);
engine.Initialize();
// select a file or set of files
OpenImageFileDialog openDialog = new OpenImageFileDialog();
openDialog.Multiselect = true;
if (openDialog.ShowDialog() == DialogResult.OK)

{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Text (*.txt)|*.txt";
if (saveFileDialog.ShowDialog() != DialogResult.OK)
return;
try

{
// translate into a plain text file
engine.Translate(
new FileSystemImageSource(openDialog.FileNames, true),
"text/plain", saveFileDialog.FileName);
}
catch (OcrException err)

{
System.Console.WriteLine("Error in OCR: " + err.Message);
}
}
engine.ShutDown();
}

As you can see, the interfacing is simple. You may also notice that the main use of the engine is the Translate method, which will takes a set of images and writes them to a file (or stream) using the given MIME type as the output format. By using the MIME standard to describe output file types, it is easy to ask the engine what output types it can support as well as to augment or replace them!
The OcrEngine maintains a collection of objects that implement an interface called ITranslator. When you request that a set of images are to be translated to an output file format, the engine will select a translator that matches the mime type.

If your task requires you to generate output in a particular format, it is short work to create your own object to translate the recognized text and images into the format that you need. You can add your new translator or take away from the engine’s translator collection as you see fit. You can even bypass the translator selection process entirely and simply supply the translator that you want to use.
OCR Engine Events
Through the familiar .NET event mechanism, you can get hooked into every step of document processing, allowing you to finely control how your images are handled. For example, you can request notification during the stage when an image is preprocessed to make it more palatable for the OCR engine, letting you alter what the engine will use for recognition.
In the following C# code snippet, you can see how to hook in your own code to do image preprocessing:
static void Main(string[] args)


{
// create and initialize the engine
ExperVisionEngine engine = new ExperVisionEngine(null, null);
engine.Initialize();

engine.PagePreprocessing +=
new OcrPagePreprocessingEventHandler(engine_PagePreprocessing);
}

private static void engine_PagePreprocessing(
object sender, OcrPagePreprocessingEventArgs e)


{
// override all options
e.OptionsOut = 0;

AtalaImage imageBW;
// convert to black and white, if needed
if (e.ImageIn.PixelFormat != PixelFormat.Pixel1bppIndexed)
imageBW = e.ImageIn.GetChangedPixelFormat(
PixelFormat.Pixel1bppIndexed);
else
imageBW = e.ImageIn;

// Deskew the image
AutoDeskewCommand deskew = new AutoDeskewCommand();
AtalaImage imageDeskewed = deskew.ApplyToImage(imageBW);
if (imageBW != imageDeskewed && imageBW != e.ImageIn)
imageBW.Dispose();

// Hand back to the engine
e.ImageOut = imageDeskewed;
}

As you can see, the amount of work to get hooked in is small, letting you concentrate on the task: processing the image in the way that you want.
The Atalasoft OCR objects let you hook into image processing, image segmentation, and output page construction. There are also events to let you track progress of the engine on a page as well as throughout an entire document. This lets you show your users what they need to know.
Contact Atalasoft directly for more details, or download a 30 day trial of our OCR engine today.
摘要: ASCII码表 信息在计算机上是用二进制表示的,这种表示法让人理解就很困难。因此计算机上都配有输入和输出设备,这些设备的主要目的就是,以一种人类可阅读的形式将信息在这些设备上显示出来供人阅读理解。为保证人类和设备,设备和计算机之间能进行正确的信息交换,人们编制的统一的信息交换代码,这就是ASCII码表,它的全称是“美国信息交换标准代码”。 八进制 十六进制 十进制...
阅读全文