`

ruby怎么取html代码中的img标签

    博客分类:
  • ruby
阅读更多
##取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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics