Recentemente um cliente solicitou para remover as aspas de um XML, estas aspas que ele queria remover eram provenientes do Word (também conhecida como aspas inglesas). A visualização deste XML não estava sendo atrapalhada por causa deste tipo de aspa nem estava gerando erro. Este XML seria usado para mostrar o conteúdo em outro site (que não se deram ao trabalho de utilizar CDATA ou converter esta aspa).

Este problema também é um pouco incomum de se resolver porque se você tentar utilizar funcções como str_replace(), alguns editores simplesmente convertem a aspa inglesa em aspa normal.

Dado o problema, eu estive pesquisando no site do php.net e em um fórum do goole e encontrei as funções abaixo (as três primeiras). A função convert_ascii() que utilizei para corrigir o problema eu encontrei na busca organica, o endereço cai direto na página do código (créditos mantidos).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function strip_quotes($text = '')
{
   $text = str_replace(array("‘", "’", "′"), "'", $text);
   $text = str_replace(array("“", "”", "″"), """, $text);
   return $text;
} 
function unhtmlentities($string)
{
   $string = preg_replace('~&#x0*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
   $string = preg_replace('~&#0*([0-9]+);~e', 'chr(\\1)', $string);
 
   // replace literal entities
   $trans_tbl = get_html_translation_table(HTML_ENTITIES);
   $trans_tbl = array_flip($trans_tbl);
   return strtr($string, $trans_tbl);
}
function unichr($u) {
   return mb_convert_encoding('&#' . intval($u) . ';', 'UTF-8', 'HTML-ENTITIES');
}
 
 
/**
* Remove any non-ASCII characters and convert known non-ASCII characters
* to their ASCII equivalents, if possible.
*
* @param string $string
* @return string $string
* @author Jay Williams <myd3.com>
* @license MIT License
* @link http://gist.github.com/119517
*/
function convert_ascii($string)
{
  // Replace Single Curly Quotes
  $search[] = chr(226).chr(128).chr(152);
  $replace[] = "'";
  $search[] = chr(226).chr(128).chr(153);
  $replace[] = "'";
 
  // Replace Smart Double Curly Quotes
  $search[] = chr(226).chr(128).chr(156);
  $replace[] = '"';
  $search[] = chr(226).chr(128).chr(157);
  $replace[] = '"';
 
  // Replace En Dash
  $search[] = chr(226).chr(128).chr(147);
  $replace[] = '--';
 
  // Replace Em Dash
  $search[] = chr(226).chr(128).chr(148);
  $replace[] = '---';
 
  // Replace Bullet
  $search[] = chr(226).chr(128).chr(162);
  $replace[] = '*';
 
  // Replace Middle Dot
  $search[] = chr(194).chr(183);
  $replace[] = '*';
 
  // Replace Ellipsis with three consecutive dots
  $search[] = chr(226).chr(128).chr(166);
  $replace[] = '...';
 
  // Apply Replacements
  $string = str_replace($search, $replace, $string);
 
  // Remove any non-ASCII Characters
  $string = preg_replace("/[^\x01-\x7F]/","", $string);
 
  return $string;
}

Espero que ajudem vocês.