求一个Php 提取表格内容的正则表达式 字符串可能如下: $s1 = '这里是描述字符( )
';
$s2= ’这里是描述字符( )
0
';
希望能把table表格前的字符 :这里是描述字符( )’ 和 td 中间的字符串提取出来
'BBBBB '、'AAAAA'、'
'、'
0 '
表格td中间内容可能比较杂,尽量考虑各种情况。
不知道描述得清楚么? 各位正则达人请支招!
------解决思路---------------------- $s1 = '这里是描述字符( )<table name="optionsTable" cellpadding="0" cellspacing="0" width="100%"><tr><td width="25%">AAAAA </td><td width="25%"> BBBBB </td></tr></table>';<br />$s2= '这里是描述字符( )<table name="optionsTable" cellpadding="0" cellspacing="0" width="100%"><tr><td width="50%"><img src="2061.png" style="max-width:90%" / alt="Php 提取表格内容的正则表达式" > </td><td width="50%"> <sub>0</sub></td></tr></table>';<br />//匹配table前面的内容<br />preg_match_all('/(.+?)<table[^>]+?>/i',$s1,$p1);<br />echo "<pre class="brush:php;toolbar:false">";<br />print_r($p1[1]);<br />echo " Copy after login
";
//匹配td里面的内容
preg_match_all('/
]+?>(.+?)<\/td>/i',$s2,$m2); echo "";<br />print_r($m2[1]);<br />echo " Copy after login
"; //$p1[1]和$m2[1]就是匹配到的内容------解决思路---------------------- <br /><?php<br /><br />$s1 = '这里是描述字符( )<table name="optionsTable" cellpadding="0" cellspacing="0" width="100%"><tr><td width="25%">AAAAA </td><td width="25%"> BBBBB </td></tr></table>';<br /><br />$s2 = '这里是描述字符( )<table name = "optionsTable" cellpadding = "0" cellspacing = "0" width = "100%"><tr><td width = "50%"><img src = "2061.png" style = "vertical-align:middle;" / alt="Php 提取表格内容的正则表达式" > </td><td width = "50%"> <sub>0</sub></td></tr></table>';<br /><br />//换个思路吧,不要提取而是删减<br />//包括table/tr标签就再加2条<br />$replace = array('/<\s*td.*>/U', '/<\s*\/td\s*>/U');<br /><br />echo preg_replace($replace, '', $s1);<br />echo '<br />';<br />echo preg_replace($replace, '', $s2);<br /><br /> Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
2024-10-22 09:46:29
2024-10-13 13:53:41
2024-10-12 12:15:51
2024-10-11 22:47:31
2024-10-11 19:36:51
2024-10-11 15:50:41
2024-10-11 15:07:41
2024-10-11 14:21:21
2024-10-11 12:59:11
2024-10-11 12:17:31