D.k
D.k

Reputation: 462

How to remove special characters in php

Could somebody tell me how to remove special characters from below array in php

Array
(
[users] => Array
    (
        [name] => ASSOCIATION OF�CHIEFS OF USERS            
    )
)

Output Expected : ASSOCIATION OF CHIEFS OF USERS

Thanks

Upvotes: 0

Views: 496

Answers (2)

RomanPerekhrest
RomanPerekhrest

Reputation: 92854

The solution using preg_replace function:

$arr = ['users' => ['name' => 'ASSOCIATION OF�CHIEFS OF USERS']];
$arr['users']['name'] = preg_replace("/[^\w [:punct:]]+/i", " ", $arr['users']['name']);

print_r($arr);

The output:

Array
(
    [users] => Array
        (
            [name] => ASSOCIATION OF CHIEFS OF USERS
        )
)

Upvotes: 1

Oto Shavadze
Oto Shavadze

Reputation: 42753

Just use str_replace()

echo str_replace ("�", " ", "ASSOCIATION OF�CHIEFS OF USERS");

Upvotes: 0

Related Questions