замените все элементы, кроме букв английского алфавита, цифр и символов клавиатуры, в строке php - PullRequest
0 голосов
/ 30 марта 2019

У меня есть строка php, которая может содержать китайские и другие символы, которые не являются utf8. Мне нужно удалить все это и сохранить только английские алфавиты, цифры, общие символы и пробелы.

Я попробовал такое регулярное выражение

    $text = preg_replace('/[^A-Za-z0-9\-]/', ' ', $words);

Но я не получаю желаемый результат. Моя строка будет выглядеть так:

l 2014 ;59:316 �猫聦聙 Efficacy and Safety of Terbinafine Hydrochloride 1% Cream vs. Sertaconazole Nitrate 2% Cream in Tinea Corporis and Tinea Cruris: A Comparative Therapeutic Trial .Indian Journal of Dermatology 2013 ;58(6):457 - 460 �猫聦聙 Congenital cutis laxa with rectal and uterovaginal prolapse. Indian J Dermatol Venereol Leprol 2011 ;77:321 - 4 �猫聦聙 Dermatitis neglecta. Indian J Dermatol Venereol Leprol 2011 ;77:62 - 3 �猫聦聙 Ichthyosis bullosa of Siemens sans history of blistering: an interesting case report Journal of Pakistan Association of Dermatologists 2009 ; 19: 171 - 174 Paper presentations �猫聦聙 Study of Autologous Serum Skin Test In Chronic Idiopathic Urtic aria at Cuticon conference , Dec 2010 �猫聦聙 Scenerio of Leprosy at Tertiary Care Level Centre In Rural Central India at Cuticon conference , Nov 2009 Poster presentations �猫聦聙 Extrav

Я хочу удалить �猫聦聙 подобные вещи.

1 Ответ

0 голосов
/ 30 марта 2019

Похоже, что вы хотите сохранить только печатные символы ASCII и хотите избавиться от остальных.

Вы можете использовать это регулярное выражение, которое сохранит все печатные символы ascii и удалит остальные символы,

[^ -~]+

Это регулярное выражение в основном использует набор символов дальнего боя, начиная с пробела до последнего символа ascii, который является тильдой.

Демонстрационная версия

Дайте мне знать, если это работает для вас.Если вы хотите дополнительно исключить еще несколько символов из списка ASCII, это легко сделать.Просто дайте мне знать.

Демонстрация PHP-кода,

$words = "l 2014 ;59:316 �猫聦聙 Efficacy and Safety of Terbinafine Hydrochloride 1% Cream vs. Sertaconazole Nitrate 2% Cream in Tinea Corporis and Tinea Cruris: A Comparative Therapeutic Trial .Indian Journal of Dermatology 2013 ;58(6):457 - 460 �猫聦聙 Congenital cutis laxa with rectal and uterovaginal prolapse. Indian J Dermatol Venereol Leprol 2011 ;77:321 - 4 �猫聦聙 Dermatitis neglecta. Indian J Dermatol Venereol Leprol 2011 ;77:62 - 3 �猫聦聙 Ichthyosis bullosa of Siemens sans history of blistering: an interesting case report Journal of Pakistan Association of Dermatologists 2009 ; 19: 171 - 174 Paper presentations �猫聦聙 Study of Autologous Serum Skin Test In Chronic Idiopathic Urtic aria at Cuticon conference , Dec 2010 �猫聦聙 Scenerio of Leprosy at Tertiary Care Level Centre In Rural Central India at Cuticon conference , Nov 2009 Poster presentations �猫聦聙 Extrav";
echo preg_replace('/[^ -~]+/', '', $words);

Печать только ваших предполагаемых символов.

l 2014 ;59:316  Efficacy and Safety of Terbinafine Hydrochloride 1% Cream vs. Sertaconazole Nitrate 2% Cream in Tinea Corporis and Tinea Cruris: A Comparative Therapeutic Trial .Indian Journal of Dermatology 2013 ;58(6):457 - 460  Congenital cutis laxa with rectal and uterovaginal prolapse. Indian J Dermatol Venereol Leprol 2011 ;77:321 - 4  Dermatitis neglecta. Indian J Dermatol Venereol Leprol 2011 ;77:62 - 3  Ichthyosis bullosa of Siemens sans history of blistering: an interesting case report Journal of Pakistan Association of Dermatologists 2009 ; 19: 171 - 174 Paper presentations  Study of Autologous Serum Skin Test In Chronic Idiopathic Urtic aria at Cuticon conference , Dec 2010  Scenerio of Leprosy at Tertiary Care Level Centre In Rural Central India at Cuticon conference , Nov 2009 Poster presentations  Extrav

Демонстрация PHP PHP

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...