0

I have a problem with strinngs encoding, the special chars, quotes etc.. are encoded like this: " '

And I want to remove the hash and replace the strings with the utf-8 textual encoding like: " and &apos

The goal is to replace all strings found in this link: https://alexandre.alapetite.fr/doc-alex/alx_special.html

from the 3rd column to use the strings of the second one.

Any help to do that?

Bizboss
  • 7,792
  • 27
  • 109
  • 174

1 Answers1

0

Using the array from this answer: https://stackoverflow.com/a/11179875/3578036

$string = 'Some <b>bold</b> text & <i>italic</i>';
$string = htmlspecialchars($string);
$translated = strtr($string, $HTML401NamedToNumeric);

Which would return the following at each step:

  1. Base: Some <b>bold</b> text & <i>italic</i>
  2. Special chars: Some &lt;b&gt;bold&lt;/b&gt; text &amp; &lt;i&gt;italic&lt;/i&gt;
  3. Translated: Some &#60;b&#62;bold&#60;/b&#62; text &#38; &#60;i&#62;italic&#60;/i&#62;

Aside from that, you really need to supply more code.


The string is required to be converted to special chars because of the way the strtr function works by checking the array keys; and since the array keys are stored as HTML entities, this must be the case for the replacements. Ergo, removing the htmlspecialchars line will result in the exact same string being output. This could be resolved by replacing the array keys with the actual character and not the entity, but that will require more work on your part.

JustCarty
  • 3,839
  • 5
  • 31
  • 51