1

I need to extract the xhpc_composerid and targetid values

I used php to do so

it is of format

\" name=\"xhpc_composerid\" value=\"u195493_3\" \/>\u003cinput type=\"hidden\" autocomplete=\"off\" name=\"xhpc_targetid\" value=\"599498849\" \/>\u003cinput type=\"hidden\" autocomplete=\"off\" name=\"xhpc_context\" value=\

i used the regular expression

preg_match_all("/\\\"xhpc_composerid\\\" value=\\\"(.*?)\\\"/",$proPage,$xhpc_composerid);

where proPage contains the page data but dont know why i am not getting any results in $xhpc_composerid what am i doing wrong?

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
  • 6
    Any reason not to use a HTML parser instead? – Pekka Feb 23 '11 at 09:53
  • I think we should have a new close reason for the html parsing problem, with a link to this page : http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – greg0ire Feb 23 '11 at 10:01
  • 1
    @greg0ire no, we shouldnt, because the accepted answer is wrong. You *can* parse HTML with Regex. You just shouldnt do it in most cases, because parsing HTML is a solved problem and there is parsers out there that can do so more reliably than what users usually come up with. If you want to link to anything, link to [Best Methods to parse HTML](http://stackoverflow.com/questions/3577641/best-methods-to-parse-html/3577662#3577662) or [Robust and mature HTML parser](http://stackoverflow.com/questions/292926/robust-mature-html-parser-for-php) – Gordon Feb 23 '11 at 10:08
  • @Shashank why are the quotes escaped? Where does that data come from? – Gordon Feb 23 '11 at 10:10
  • @Gordon the data came from the facebook profile page btw didn't knew about HTML parsing thanks for the links will learn something new today :D – Shashank amin Feb 23 '11 at 12:49

2 Answers2

1

This regex worked for me on you example:

\\"xhpc_composerid\\" value=\\"(.+?)\\"

But generally you should use html parser to get data from html. Because what if name and value attributes become reversed or some other attribute gets in the middle of them?

Matej Baćo
  • 1,312
  • 2
  • 10
  • 12
0

var_dump($xhpc_composerid);

and let us know what value it holds.

The regex does work.

Bellyboy
  • 36
  • 2