English 中文(简体)
Parse/2005/4 with php regex
原标题:Parse block with php regex

I m trying to write a (I think) pretty simple RegEx with PHP but it s not working. Basically I have a block defined like this:

%%%%blockname%%%%
stuff goes here
%%%%/blockname%%%%

我不喜欢Ref,但这是我尝试的:

preg_match_all( /^%%%%(.*?)%%%%(.*?)%%%%/(.*?)%%%%$/i ,$input,$matches);

它返回了一个有4个空条目的阵列。

我也认为,除了实际工作外,这还需要第三者的某些点子,因为它应当等同于第一个点?

请告诉我:

最佳回答

You need to allow the dot to match newlines, and to allow ^ and $ to match at the start and end of lines (not just the entire string):

preg_match_all( /^%%%%(.*?)%%%%(.*?)%%%%/(.*?)%%%%$/sm ,$input,$matches);

s (single-line) 备选办法使斜线与包括新线在内的任何特性相符。

<代码>m(多线)选项允许<编码>>>><>>>>>> ><$在行文开始和结尾处匹配。

<代码>i备选办法在您的名册上没有必要,因为其中不存在对案件敏感的特点。

回答你提问的第二部分: 如果<代码>blockname在这两种情况下都是一样的,那么你可以通过提及第一组捕获组来表明这一点:

preg_match_all( /^%%%%(.*?)%%%%(.*?)%%%%/1%%%%$/sm ,$input,$matches);
问题回答

我很相信你会 t,因为这些行动需要拯救一个变量,你可以 t。 你们应努力利用PHP的建构,以达到标价。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签