PHP remove characters with hyphens above them like (é) [duplicate] - php

This question already has answers here:
Change foreign characters to their roman equivalent
(7 answers)
Closed 8 years ago.
Is there any possible way of doing this in PHP? Eg convert the word Québec
$str = 'Québec';
echo convert($str);
result:
Quebec

Those are called diacritics (or accents). The process of converting some text from one script to another (e.g. one with diacritics to one without) is called transliteration and PHP has a module for performing it.
You probably want something like:
transliterator_transliterate('Any-Latin; Latin-ASCII', $your_input);

Related

php - convert string to uuid version 4 format [duplicate]

This question already has answers here:
Format 32-character string with hyphens to become UUID
(3 answers)
Closed 7 months ago.
I want convert this string to uuid4 by PHP functions
my string: 24:1D:87:0E:01:32:09:FB:36:97:23:BD:B5:E1:18:04
convert to : 241d870e-0132-49fb-b697-23bdb5e11804
how can do it?! php have function or?!...
You could do a combination of:
str_replace() to strip out the : colons
substr() the sections you need
and concat them with . "-" .
lastly apply strtolower() if that's really required
Or, you could write a regex/preg_replace transformation.

How can I prevent unicode characters like this Ả̴̢̦̙̬̲̯̖̲̟̟̬̲̻̣̩͕͍̦͍̮̠̤͇̿́̾͋́̾̎̔̐̓̾̐̉͒̅͛̈́̀̇͋͋̔̕͘͝͝͝ on my site and why do they exist? [duplicate]

This question already has answers here:
How does Zalgo text work?
(2 answers)
What's up with these Unicode combining characters and how can we filter them?
(4 answers)
Closed 3 years ago.
How to prevent characters like this one on my website:
Ả̴̢̦̙̬̲̯̖̲̟̟̬̲̻̣̩͕͍̦͍̮̠̤͇̿́̾͋́̾̎̔̐̓̾̐̉͒̅͛̈́̀̇͋͋̔̕͘͝͝͝
They are really annoying. Ḧ̶̡̡̢͙͚̝̖͙͓̝̘̯̜̗͙̩͎̻̥̩͈͈͈̘̰͇̞͇͇̦̼̺̙̲͔́̿͌̀̅͊̌́͂̋̃̽̔̀̇̎̈̆́̽̇͂͘͘͜͝͝A̸̡̧̲̦͕̦̦̘̫͍̺͙̫͉̠͆̈́̅̚ͅͅḦ̴̪̱̠̦̜̩͒̃͌̎̇͌̒̍̒̇̾̀͑̂̆̉̓͌͘̚̚̕͜͝ͅA̶̻͐̔̍̃͆̆̓̿͋͊̽͝
Replace all the unicode characters outside of your desired range(s).
$annoying_string = 'Ả̴̢̦̙̬̲̯̖̲̟̟̬̲̻̣̩͕͍̦͍̮̠̤͇̿́̾͋́̾̎̔̐̓̾̐̉͒̅͛̈́̀̇͋͋̔̕͘͝͝͝Ả̴̢̦̙̬̲̯̖̲̟̟̬̲̻̣̩͕͍̦͍̮̠̤͇̿́̾͋́̾̎̔̐̓̾̐̉͒̅͛̈́̀̇͋͋̔̕͘͝͝͝Ả̴̢̦̙̬̲̯̖̲̟̟̬̲̻̣̩͕͍̦͍̮̠̿́̾͋́̾̎̔̐̓̾̐̉͒̅͛̈́̀̇͋͋̔̕͘͝͝͝foobar̤͇';
$cleaned_string = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $annoying_string);
echo $cleaned_string; // AAAfoobar

Convert Unicode escape sequence to UTF-8 [duplicate]

This question already has answers here:
Unicode character in PHP string
(8 answers)
Closed 2 years ago.
I'm trying to convert some characters with PHP before inserting to MySQL DB a JSON object with this kind of data:
\u00c9
that means: É
I tried this but it didn't work:
echo utf8_encode(print_r('\u00c9'));
I've read that it's in Unicode but i can't find the way to print it before inserting it. Any ideas?
Take a look at this answer. TL;DR:
echo json_decode('"\u00c9"');

how to remove � sign in php while displaying content from mysql table [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 8 years ago.
The web page shows the content as below
Golden Temple�is a Sikh�Gurdwara�located in the city
of�Amritsar,�Punjab,�India. It was built by�Guru Arjan, in the 16th
Century.
but the actual content is as below
Golden Temple is a Sikh Gurdwara located in the city of
Amritsar,Punjab,India. It was built by Guru Arjan, in the 16th
Century.
please help me
Try with
$result = preg_replace('/[^\x00-\x7F]+/', '', $dbstring); // remove all non-ASCII (so called special) characters from your string:
or
$result=utf8_encode($dbstring); // encodes an ISO-8859-1 string to UTF-8

Special characters within the code - PHP [duplicate]

This question already has answers here:
Special characters in property name of object
(2 answers)
Closed 9 years ago.
in my code i have to show some element of an object ( a xml file), but the problem i am having is that the names of the elements contain special characters like "é", "à", "è" "ç" etc...
so when i try for example t show :
echo $xml->CoordonnéesNum->Téléphone;
it doesn't work, so i have to change it to something like this :
$xml->Coor->Tel //without the special characters
but i have thousands of xml files in wich these elements are named with these special characters and i cannot change them all manually
i have to mention that im new to php:
so please if you can help to fix this issue that would be wonderful.
Try this instead:
echo $xml->{"CoordonnéesNum"}->{"Téléphone"};

Categories