求助一个正则表达式

常的河 2013-01-29 04:20:16

<tr onMouseOver="overCell(this);" onMouseOut="outCell(this);"><td width="30%" class=style2><a href="/products/50-00-0.htm" class=blue //onclick="blur()">
CAS#
</a></td><td width="70%" class=style2>
化学名
</td></tr>
<tr onMouseOver="overCell(this);" onMouseOut="outCell(this);"><td width="30%" class=style2><a href="/products/50-00-0.htm" class=blue //onclick="blur()">
CAS#
</a></td><td width="70%" class=style2>
化学名
</td></tr>
<tr onMouseOver="overCell(this);" onMouseOut="outCell(this);"><td width="30%" class=style2><a href="/products/50-00-0.htm" class=blue //onclick="blur()">
CAS#
</a></td><td width="70%" class=style2>
化学名
</td></tr>


求助一个正则表达式,将表格中的CAS#和化学名提取到一个二维数组中,谢谢

...全文
427 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
常的河 2013-01-30
  • 打赏
  • 举报
回复
以解决,将字符串中所有换行去除就可以了,谢谢jordan
常的河 2013-01-30
  • 打赏
  • 举报
回复
引用 1 楼 jordan102 的回复:
PHP code?12345678910111213141516171819$s=<<<html<tr onMouseOver="overCell(this);" onMouseOut="outCell(this);"><td width="30%" class=style2><a href="/products/50-00-0.htm" class=blue //onc……
谢谢jordan的回复,这段代码能够很好的运行,但是因为获取过后的网页代码我编辑过,实际的网页格式是

<tr onMouseOver="overCell(this);" onMouseOut="outCell(this);">
<td width="30%" class=style2>
<a href="/products/50-00-0.htm" class=blue onclick="blur()">50-00-0</a>
</td>
<td width="70%" class=style2>
Formaldehyde
</td>
</tr><tr onMouseOver="overCell(this);" onMouseOut="outCell(this);">
<td width="30%" class=style2>
<a href="/products/50-01-1.htm" class=blue onclick="blur()">50-01-1</a>
</td>
<td width="70%" class=style2>
Guanidine hydrochloride
</td>
</tr>
我使用jordan的正则表达式获取到的数组是空的,请问是怎么回事,本人是正则表达式菜鸟,请多多包涵 谢谢
一起混吧 2013-01-29
  • 打赏
  • 举报
回复
$s=<<<html
<tr onMouseOver="overCell(this);" onMouseOut="outCell(this);"><td width="30%" class=style2><a href="/products/50-00-0.htm" class=blue //onclick="blur()">
    CAS#
</a></td><td width="70%" class=style2>
    化学名
</td></tr>
<tr onMouseOver="overCell(this);" onMouseOut="outCell(this);"><td width="30%" class=style2><a href="/products/50-00-0.htm" class=blue //onclick="blur()">
    CAS#
</a></td><td width="70%" class=style2>
    化学名
</td></tr>
<tr onMouseOver="overCell(this);" onMouseOut="outCell(this);"><td width="30%" class=style2><a href="/products/50-00-0.htm" class=blue //onclick="blur()">
    CAS#
</a></td><td width="70%" class=style2>
    化学名
</td></tr>
html;
preg_match_all('/>([^>]+)<\/a><\/td><td width="70%" class=style2>(.+)<\/td>/isU',$s,$m);
print_r($m);

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧