Clear data from php html page

I need to clear data from html page

<div style="margin-top: 0px; padding-right: 5px;" class="lftFlt1">

    <a href="" onclick="setList1(157204);return false;" class="contentSubHead" title="USA USA">USA USA</a>
    <div style="display: inline; margin-right: 10px;"><a href="" onclick="rate('157204');return false;"><img src="http://icdn.raaga.com/3_s.gif" title="RATING: 3.29" style="position: relative; left: 5px;" height="10" width="60" border="0"></a></div>
    </div>

I need to clear US USA and 157204 from onclick="setList1...

0
source share
5 answers

You must use DOMDocument or XPath . RegEx is usually not recommended for HTML parsing.

+2
source

Use regex:

/setList1\(([0-9]+)\)[^>]+title="([^"]+)"/si

and preg_match () or preg_match_all ()

+1
source

, HTML DOM.

XPath, :

//a/text()

XPath, title :

//a/@title

XPath, onclick :

//a/@onclick

You will need to use some string function to extract the number from the onclick text.

+1
source

To date, the best lib for curettage is a simple html dom. mainly uses jquery selector syntax.

http://simplehtmldom.sourceforge.net/

How do you get the data in this example:

include("simple_html_dom.php");
$dom=str_get_html("page.html");
$text=$dom->find(".lftFlt1 a.contentSubHead",0)->plaintext;
//or 
$text=$dom->find(".lftFlt1 a.contentSubHead",0)->title;
0
source

I did it this way

$a=$coll->find('div[class=lftFlt1]');
$text=$element->find("a[class=cursor]",0)->onclick;
0
source

Source: https://habr.com/ru/post/1784060/


All Articles