检测mp4文件(Detect mp4 files)
我必须设计一个检测mp4文件的模块。 如果将任何随机文件作为输入,它必须告诉它是否是一个mp4文件。 在哪里可以找到mp4文件的标题规范? 尝试谷歌搜索除了签名之外找不到任何东西。 关于模块的C编程的其他任何提示?
I have to design a module that detects mp4 files. If will get any random file as input and it has to tell whether it is a mp4 file or not. Where can I find the specification of headers for the mp4 file? Tried googling but could not find anything except the signature. Any other tips regarding C programming for the module?
原文:https://stackoverflow.com/questions/13190005
最满意答案
这是您目前正在考虑的非常糟糕的解决方案:
<span\b[^<>]*\bid="ctl00_MainContent_ListView2_ctrl2_ctl01_[^"]*"[^<>]*475px;">(.*?)</span><br\s*/>
见演示
它确保我们找到了一个
<span>
标签,并且有一个以ctl00_MainContent_ListView2_ctrl2_ctl01_
开头的id
属性,并且有一些以475px;
结尾的属性(你知道它是style
)475px;
,然后我们只捕获任何截至</span>
标记的内容。您可以使用DOM和XPath来实现这一点,这是一个更安全的解决方案,它使用与上面相同的逻辑:
$html = "<span id=\"ctl00_MainContent_ListView2_ctrl2_ctl01_Label17\" class=\"vehicledetailTable\" style=\"display:inline-block;width:475px;\">OWNED</span><br />"; $dom = new DomDocument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); $spans = $xpath->query("//span[starts-with(@id,'ctl00_MainContent_ListView2_ctrl2_ctl01_') and @class='vehicledetailTable' and contains(@style,'475px;')]"); $data = array(); foreach ($spans as $span) { array_push($data, $span->textContent); } print_r($data);
输出:
[0] => OWNED
注意XPath表达式包含3个条件,随意修改任何:
//span
- 获取所有span标签starts-with(@id,'ctl00_MainContent_ListView2_ctrl2_ctl01_')
- 有一个属性id
,其值以ctl00_MainContent_ListView2_ctrl2_ctl01_
@class='vehicledetailTable'
- 并且class
属性的值等于vehicledetailTable
contains(@style,'475px;')
- 并且有一个style
属性,其值包含475px;
。条件包含在
[...]
,并与or
或and
。 它们也可以用圆括号分组。 您也可以使用not(...)
来反转条件。 XPath在这种情况下非常有用。Here is a very poor solution that you are currently considering:
<span\b[^<>]*\bid="ctl00_MainContent_ListView2_ctrl2_ctl01_[^"]*"[^<>]*475px;">(.*?)</span><br\s*/>
See demo
It makes sure we found a
<span>
tag and there isid
attribute starting withctl00_MainContent_ListView2_ctrl2_ctl01_
, and there is some attribute (and you know it isstyle
) ending with475px;
, and then we just capture anything up to the closing</span>
tag.You can get this with DOM and XPath, which is a much safer solution that uses the same logic as above:
$html = "<span id=\"ctl00_MainContent_ListView2_ctrl2_ctl01_Label17\" class=\"vehicledetailTable\" style=\"display:inline-block;width:475px;\">OWNED</span><br />"; $dom = new DomDocument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); $spans = $xpath->query("//span[starts-with(@id,'ctl00_MainContent_ListView2_ctrl2_ctl01_') and @class='vehicledetailTable' and contains(@style,'475px;')]"); $data = array(); foreach ($spans as $span) { array_push($data, $span->textContent); } print_r($data);
Output:
[0] => OWNED
Note that the XPath expression contains 3 conditions, feel free to modify any:
//span
- get all span tags thatstarts-with(@id,'ctl00_MainContent_ListView2_ctrl2_ctl01_')
- have an attributeid
with value starting withctl00_MainContent_ListView2_ctrl2_ctl01_
@class='vehicledetailTable'
- and haveclass
attribute with value equal tovehicledetailTable
contains(@style,'475px;')
- and have astyle
attribute whose value contains475px;
.Conditions are enclosed into
[...]
and are joined withor
orand
. They can also be grouped with round brackets. You can also usenot(...)
to invert the condition. XPath is very helpful in such situations.
相关问答
更多-
表达方式 {{\*(\w+)}}((?:.|\n)+?){{\/\w+}} 非常无效,更好用 {{\*(\w+)}}(.+?){{/\w+}} 与其他分隔符,例如~代替。 您的旧表达式需要 780步 (请参阅 regex101.com上的此演示 ),而后者只需要 404步 (请参阅 此处的另一个演示 )。 The expression {{\*(\w+)}}((?:.|\n)+?){{\/\w+}} is very ineffective, better use {{\*(\w+)}}(.+?){{/ ...
-
'/{if\s+(isRegion|isCountry)([az]+?)}/i'对我来说很好。 在这里看到它。 '/{if\s+(isRegion|isCountry)([a-z]+?)}/i' works just fine for me. See it in action here.
-
您只能获得组的最后一场比赛。 两个得到所有的值,如x,x; 你可以使用你当前的正则表达式,改变一下: preg_match_all('/("message":")([a-z0-9A-Z]+):(.*)"/', $customerMessage, $matches); /* $matches[3] --> 2,2;3,3; 现在你可以使用$matches[3]获得第3组并匹配所有x,x; [0-9]+,[0-9]+; preg_match_all('/[0-9]+,[0-9]+/', $matches[3] ...
-
preg_match_all()在匹配结果中返回一个数组数组。 然后显示您必须使用的所有匹配项: $remove = preg_match_all('/;([\d]{4};[\d]{3});/', $str, $m); foreach($m[0] as $item) { echo $item . '
'; } 如果您只想要捕获组的内容,只需将$m[0]替换$m[0] $m[1] preg_match_all() returns in match result an array of arrays ... -
如果我理解正确,count($ matches [0]假设$ content中只有一个匹配。 不完全的; $matches[0]表示整个正则表达式中的匹配数组(与$matches[1] ,后者是正则表达式的第一个匹配组中的匹配数组)。 因此, count($matches[0])是他第一个匹配组中的匹配数。 你可以做你所说的并将for循环重写for foreach循环,但这可能不会改变任何东西,因为两个方法都应该遍历$matches[0]所有元素。 您确定您要查找的结果是否与正则表达式相匹配? If I u ...
-
匹配通配符而不使用preg_match_all添加到数组(Matching wildcard without adding to the array with preg_match_all)[2023-10-20]
这是您目前正在考虑的非常糟糕的解决方案: ]*\bid="ctl00_MainContent_ListView2_ctrl2_ctl01_[^"]*"[^<>]*475px;">(.*?)
见演示 它确保我们找到了一个标签,并且有一个以ctl00_MainContent_ListView2_ctrl2_ctl01_开头的id属性,并且有一些以475px;结尾的属性(你知道它是style ) 475px; ,然后我们只捕获任何截至 ... -
积极的向前看 /(?=(1[^1]+1))/ 阅读: http : //www.regular-expressions.info/lookaround.html Positive lookahead /(?=(1[^1]+1))/ Read this: http://www.regular-expressions.info/lookaround.html
-
[ , ]和*是正则表达式中的特殊元字符,您需要转义它们。 您还需要根据您的问题选择last [] 。 遵循以下建议应该工作: $name = 'hello $this->row[today1][] dfh fgh df $this->row[test1] ,how good $this->row[test2][] is $this->row[today2][*] is monday'; echo $name."\n"; preg_match_all( '/\$this->row\[.*?\](?:\[ ...
-
远程文件使用序列CR LF作为换行符,这就是锚$不匹配的原因。 当您将文件内容复制/粘贴到默认情况下仅使用LF作为换行符的应用程序时,序列CR LF可能会默默地替换为LF并且您的模式可以正常工作。 解决问题的几种方法: 1)在你的模式中明确写出回车: #^BEGIN:VEVENT.*?END:VEVENT\r$#sm 如果您不希望在匹配结束时返回回车,请使用trim或将其置于先行断言中: #^BEGIN:VEVENT.*?END:VEVENT(?=\r$)#sm 。 您也可以删除$并使用与\r , \r\ ...
-
这个正则表达式应该工作: "/array\.content\(2\,\'?([0-9]+)\'?\,[^\)]*\)\;/ui" 并且在preg_match_all的参数中使用$con swiitch $result变量在这里测试: http ://regexr.com?34e0q 如果第一个参数不总是2(但是数字变量),您可以使用: "/array\.content\(\'?[0-9]+\'?,\'?([0-9]+)\'?\,[^\)]*\)\;/ui" 测试: htt ...