1

I need to replace special characters in Magento.

For example:

<?php echo $string; //echoes "ausführung"?>
  <?php if (strpos($string,"ü")!==false) 
    {echo "umlaut"}?>

My problem is that the if-statement is never true. I also tried to html_entity_decode or something, without a result.

Does anyone know how to replace special characters there? I need to use the string as a CSS class name and special characters are not allowed there.

poojan sharma
  • 1,564
  • 1
  • 9
  • 16
Reinsch
  • 482
  • 2
  • 4
  • 17

2 Answers2

0

Take a look at Mage_Core_Helper_Data::removeAccents($string, $german=false).

This should exactly do what you want, but unfourtunatly there is a bug ...

Setting $german to true doesn't work. If you want to use this, please check this: https://github.com/OpenMage/magento-lts/pull/345 and fix this "somehow" (I know ... do not touch core files :P)

diff --git a/app/code/core/Mage/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php
index dda2bd66e..07dbfd7d5 100644
--- a/app/code/core/Mage/Core/Helper/Data.php
+++ b/app/code/core/Mage/Core/Helper/Data.php
@@ -317,9 +317,9 @@ public function removeAccents($string, $german=false)

             if ($german) {
                 // umlauts
-                $subst = array_merge($subst, array(
+                $subst = array(
                     196=>'Ae', 228=>'ae', 214=>'Oe', 246=>'oe', 220=>'Ue', 252=>'ue'
-                ));
+                ) + $subst;
             }

             $replacements[$german] = array();
sv3n
  • 11,657
  • 7
  • 40
  • 73
-1

Use str_replace() instead

It replaces your character if found

Kevin Krieger
  • 338
  • 2
  • 12