0

Working with PHP DOM - HTML manipulation.

Got 2 questions

  1. Recently read that, there is better way to output special html characters (e.g. ©): DOMDocument::createEntityReference() method. Main advantage is, you don't need to use htmlentities, it will be automatically escaped. For ex: $copyright_symbol = $document->createEntityReference("copy");. Now, the problem is, where can I find characters' code reference? In my case I need php equalent of × (× symbol)
  2. What if I want to set muliple classes to element? Can I do it like that $el->setAttribute('class', 'class1 class2 ...') ??
hakre
  • 193,403
  • 52
  • 435
  • 836
Tural Ali
  • 22,202
  • 18
  • 80
  • 129
  • You can find a PHP array of [all named HTML entities in this answer on Stackoverflow](http://stackoverflow.com/a/11179875/367456). Like the PHP manual says, use them without the starting `&` and ending `;` for `DOMDocument::createEntityReference()`. – hakre Jun 23 '13 at 22:33
  • At Stackoverflow, **one question at a time**, or eventually a question and a sub-question. `setAttribute` is not a subquestion of `createEntityReference`. PS: see [this question](http://stackoverflow.com/q/13808846/287948) and [this answer](http://stackoverflow.com/a/13849787/287948) about multiple classes. – Peter Krauss Aug 13 '14 at 10:01

1 Answers1

1

here you can see character codes as well as friendly names. For your &#215, you will use "times" and for the second question, yes, you can do it like that.

Aleksandar Vucetic
  • 14,715
  • 9
  • 53
  • 56
  • One more q: Can I append multiple elements at once? – Tural Ali Jan 15 '12 at 04:24
  • 1
    as far as I know, you will have to perform createElement and then appendChild and if you want to do it for multiple elements, you should do it in a loop...or you can append prepared html as described in this answer here: http://stackoverflow.com/questions/4751437/php-dom-append-source-html-to-a-domelement – Aleksandar Vucetic Jan 15 '12 at 04:29
  • There are a possibility of express [numeric entities](https://en.wikipedia.org/wiki/Numeric_character_reference) with another DOMDocument method? – Peter Krauss Aug 13 '14 at 10:04