Avinash
Avinash

Reputation: 6174

how to remove all utf-8 characted from string using php

I have a problem as below. I have one xml which contain utf-8 characters but the data of this xml will get displayed on page with iso encoding.

So I have to remove this utf-8 charactres from string, How can I do this.

Thanks Avinash

EDIT:

I have used : iconv("ISO-8859-1", "UTF-8", str_replace('&','and',removeEmptyLines(strip_tags($value))))

and now its displaying  in xml file.

How can I remove this...

Upvotes: 1

Views: 1639

Answers (2)

Gumbo
Gumbo

Reputation: 655159

You can represent the Unicode characters with character references by using mb_convert_encoding:

mb_substitute_character('entity');
echo mb_convert_encoding($str, 'ISO-8859-1', 'UTF-8');

With mb_substitute_character you specify how invalid characters (characters of the input character set that are not present in the output character set) should be handled. In this case entity specifies to replace invalid characters by a corresponding HTML character reference.

Upvotes: 0

turbod
turbod

Reputation: 1988

Use the iconv function:

 iconv('utf-8','iso-8859-1//TRANSLIT',$text);

Upvotes: 1

Related Questions