0

I want to get the content inside this meta tag <meta content="Rs.55.09" itemprop="price"> or immediately after the meta tag (<meta content="Rs.55.09" itemprop="price"> Rs.55.09 ) ie the price of the product is needed.Is there any regular expression to grab the data.

Thanks in advance...

Josnidhin
  • 12,469
  • 9
  • 42
  • 61
Balu
  • 607
  • 3
  • 11
  • 24
  • what have you tried so far? Please show us your code, the errors it produces if any and the data you're working on – Harald Brinkhof Jun 13 '12 at 10:32
  • Do you have a string containing just that `` tag, or is it part of a larger document? – DaveRandom Jun 13 '12 at 10:34
  • @HaraldBrinkhof: I am doing an application in which,when a user search for google apps,it will return the details of app like package id,title,screenshots url and price.I am getting the url of apps.Now i want to grab the content(price,rating etc) of that url. – Balu Jun 13 '12 at 10:38

1 Answers1

3

This works:

preg_match('/<meta content=\"(.*?)\" itemprop=\"price\">/i', $data, $matches);

However, I'd greatly recommend looking into DOMDocument or another HTML parser, because regex is not recommended for parsing HTML like this.

Read more about HTML parsers here or read more about why not to use regex here.

Community
  • 1
  • 1
Jeroen
  • 13,056
  • 4
  • 42
  • 63
  • :It is not working.should I use index with $matches like $matches[0]. – Balu Jun 13 '12 at 10:57
  • `echo $matches[1];`, but with some simple trial and error, you could have found that out yourself... – Jeroen Jun 13 '12 at 10:59
  • 1
    @Balu: hu? yes, you should...and maybe you should read up on the regex functions in PHP before using them ;) -> php.net/manual/en/function.preg-match.php (and follow Jeroens advise regarding the parsers) – cypherabe Jun 13 '12 at 11:00