日期:2014-05-17  浏览次数:20656 次

ruby怎么取html代码中的img标签
##取html代码中的第一张图片
  def get_pic
    con=""
    if self.content!=nil
      self.content=self.content.force_encoding('utf-8')
      con=/(<img).+(src=\"?.+)\/(.+\.(jpg|gif|bmp|bnp|png)\"?).+>/.match(self.content)
      con=con.to_s.split("/>")[0]+"/>"
      return con.html_safe
    else
      return ""
    end
  end