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.

2 Answers 2

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

Use str_replace() instead

It replaces your character if found

2
  • doenst work either
    – Reinsch
    Commented Jan 4, 2016 at 15:49
  • How does your code look like? Commented Jan 5, 2016 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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