0

I want to replace all special character (in array), I used htmlspecialchars, but it does not work I found empty result !!

this is my instruction:

str_replace( array('è','é','ê','ë'), 
             array('e','e','e','e'), 
             htmlspecialchars(strtolower("Elément")) );

thank's for helping...

ghazi
  • 59
  • 1
  • 9

2 Answers2

1

Short answer: you must use mb_strtolower instead strtolower,

run the snippet below you will find why:

<?php

$a = str_replace( array('è','é','ê','ë'), array('e','e','e','e'), htmlspecialchars(strtolower("Elément")) );

echo "\n0.".$a;
echo "\n1.".htmlspecialchars(strtolower("Elément"));
echo "\n2.".strtolower("Elément");
echo "\n3.".mb_strtolower("Elément");
echo "\n4.".htmlspecialchars(mb_strtolower("Elément"));

$a = str_replace( array('è','é','ê','ë'), array('e','e','e','e'), htmlspecialchars(mb_strtolower("Elément")) );


echo "\n5.".$a;

see also enter link description here

Yu Jiaao
  • 4,444
  • 5
  • 44
  • 57
0

You could use a slugger, such as https://packagist.org/packages/javiereguiluz/easyslugger

Giso Stallenberg
  • 942
  • 7
  • 10