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.


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();

Use str_replace() instead

It replaces your character if found

  • doenst work either
    – Reinsch
    Jan 4 '16 at 15:49
  • How does your code look like? Jan 5 '16 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.