Search code examples
phphtmlsimple-html-dom

Using simplehtmldom in PHP how do I get the data-href attribute?


I am using this PHP library to work with a dom :http://simplehtmldom.sourceforge.net/

I am wanting to access the data-href element of a li element on this page:http://www.spareroom.co.uk/flatshare/bristol/

according to the api reference: http://simplehtmldom.sourceforge.net/manual_api.htm

This code should work - so long as $res represents the li dom node - which in my case it does:

echo $res->data-href;

However when i run that the echo is "0".... when I would expect to see something like :

"/flatshare/fad_click.pl?fad_id=3248085&search_id=&offset=0&city_id=&flatshare_type=offered&search_results=%2Fflatshare%2Fbristol%2F&"

Can somebody please help me to understand what I am doing wrong


Solution

  • $res->data-href is parse as

    $res->data - href
    

    i.e. it's a subtraction, because - is not a valid character in an identifier. Try:

    $res->{"data-href"}