-1

Forgive me for possibly misusing certain terminology. I would like to:

  1. open a html/php file, with php
  2. find elements with certain class
  3. change its innerHtml basically
  4. than save the file.

I have a feeling DOMElement in php could help, since I've used it for similar things in javascript, but I am (still) unsure of its function in PHP and php.net sais a DOM document "Represents an entire HTML or XML document" (so no php/javascript containing document).

  • So: which function(s), libraries should I study to best perform those operations?
  • Possibly: Aside from php.net do you perhaps have a good tutorial for ^that^ solution?

Edit: Possibly related: Manipulate HTML from php Edit2: If I would build something with my knowledge a.t.m. it would probably be almost as violent as solutions I tried earlier: https://stackoverflow.com/a/8960363/574700

  • There will be php in the document.
  • There will be some inline css and javascript in there.
Community
  • 1
  • 1
SuperSpy
  • 1,324
  • 3
  • 13
  • 28
  • Unsure why I received -1. I tried to be specific and ask a clear question. – SuperSpy Aug 08 '14 at 21:55
  • probably cause some people here expect to see code in every question. A way of showing that you tried something before asking. I don't know. Seems like a valid question to me. – Kai Qing Aug 08 '14 at 22:12

1 Answers1

1

1.open a html/php file, with php

Include htmlsimpledom and open you php file.

$html = file_get_html('myfile.html');

2.find elements with certain class

foreach($html -> find('.class-name') as $element) 
       $element - > plaintext. '<br>';

3.change its innerHtml basically

$html -> find('.class-name') -> innertext = 'text-here';

4.then save the file.

file_put_contents($filename, $html);
LifeQuery
  • 3,202
  • 1
  • 26
  • 35