求一个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="/static/imghw/default1.png" data-src="2061.png" class="lazy" 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 " Copier après la connexion
";
//匹配td里面的内容
preg_match_all('/
]+?>(.+?)<\/td>/i',$s2,$m2); echo "";<br />print_r($m2[1]);<br />echo " Copier après la connexion
"; //$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 /> Copier après la connexion
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Derniers articles par auteur
2025-02-26 03:58:14
2025-02-26 03:38:10
2025-02-26 03:17:10
2025-02-26 02:49:09
2025-02-26 01:08:13
2025-02-26 00:46:10
2025-02-25 23:42:08
2025-02-25 22:50:13
2025-02-25 21:54:11
2025-02-25 20:45:11
Derniers numéros
2025-03-26 19:40:08
2025-03-26 12:24:37
2025-03-26 12:20:46
2025-03-21 13:39:34
2025-03-21 13:38:34
Recommandations populaires
Tutoriels populaires
Plus>
Recommandations populaires
Derniers téléchargements
Plus>