简体   繁体   中英

How to parse curl response with no html <head> <body>?

So the response I got from curl is a part of the <body> .

It starts with tag <input > not with the <html><head><body> .

How do I parse it? I've tried with simple_html_dom with no result , should I use regex instead?

Try using the DOMDocument object, the loadHTML method should accept html fragments and do the parsing for you.

$doc = new DOMDocument;
$doc->loadHtml($fragment);
$html = $doc->saveHTML();

Watch out for the potential warnings generated by parsing malformed html.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM