-2

I will extract a specific information from an HTML webpage via PHP. After I don't how to extract all the value between <span class="fpStriked">....</span> for example.

$url = 'https://www.amazon.com/s/ref=nb_sb_noss_2?url=search-alias%3Daps&field-keywords=ordinateur';

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 10.10; labnol;) ctrlq.org");
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($curl);
curl_close($curl);

$myarray = array($html);
Neil
  • 14,063
  • 3
  • 30
  • 51
yokogeri
  • 1,217
  • 2
  • 8
  • 11
  • `document.getElementsByClassName("fpStriked").innerHTML` ? – Muhammad Usman Nov 19 '17 at 19:32
  • @UsmanRana `getElementsByClassName` returns a collection – charlietfl Nov 19 '17 at 19:35
  • Extract it where ... in php or in client using javascript? Do what with it? Question is too broad and doesn't include sample input or expected results. Take some time to read [ask] and [mcve] – charlietfl Nov 19 '17 at 19:37
  • Also please do some research before asking. How to work with parsing html in either language can easily be searched – charlietfl Nov 19 '17 at 19:39
  • yes. I just though OP wants everything inside the mentioned element.and I expect he would know how to loop to get the related stuff – Muhammad Usman Nov 19 '17 at 19:39
  • Possible duplicate of [How do you parse and process HTML/XML in PHP?](https://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) –  Nov 19 '17 at 20:28

1 Answers1

0

If you want to extract all text within any tags, the simple way is to strip the tags: strip_tags()

If you want to remove specific tags, maybe this SO questions helps.

you might want to take a look at PHP Simple HTML DOM Parser or similar:

for example:

// Create DOM from URL or file
$html = str_get_html($html);

or if you want to do the same at client side using JavaScript then you can use:

document.getElementsByClassName("fpStriked").innerHTML

Mayur Agarwal
  • 869
  • 10
  • 28