Special characters within the code - PHP [duplicate] - php

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"};

Related

PHP: To decode json to chinese and smily not works? [duplicate]

This question already has answers here:
Unicode character in PHP string
(8 answers)
Closed 8 years ago.
To decode json to chinese:
json_decode('"\ud83d\ude18\ud83d\ude18\ud83d\ude18\ud83d\ude18\u597d\u5bb6\u4f19\ud83d\ude0d\ud83d\ude0d\ud83d\ude0d"');
not works?
It works for chinese but not for smily
can you please give me any idea for it
that's not a valid JSON string -- JSON strings must be inside double quotes
Edit: took the failing example above, wrapped the utf-8 in doublequotes, and it decoded:
var_dump(json_decode('"\ud83c\udf83\ud83c\udf83\ud83c\udf83"'));
string(12) "🎃🎃🎃"
(I don't know what the glyphs should look like, I don't eve know if I have the right fonts installed, but the string decoded)

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"');

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

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);

htmlspecialchars() x htmlentities() [duplicate]

This question already has answers here:
htmlentities() vs. htmlspecialchars()
(12 answers)
Closed 8 years ago.
I have read their documentation, but I still don't get when to use each of them and their difference.
Let's consider the situation of having a general string in a variable and needing to echo it inside HTML code. If it has any HTML markup in it, I want it converted to HTML code (< replaced by <, & replaced by &. If it has UTF special chars that aren't available in HTML code, it's replaced by HTML number (• replaced by •).
What's the best function for that?
A harder need: unprintable chars, like \n, char(10), char(13), etc, be replaced by their number code, in the case the string is printed inside <pre> or any special textarea so that the string be dumped.
htmlentities is a workaround for not having set the character type of the document properly. htmlspecialchars is the correct function to use for merely writing text into an HTML document.
As to your second question, I think you're looking for addcslashes.

Removing/Replacing ” from string [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to decode numeric HTML entities in PHP
How does one remove/replace ” characters from a string?
I've tried html_entity_decode but it don't seem to work. There are other similar characters in the string that don't seem to be converted or removed.
Any ideas?
The issue is that html_entity_decode() doesn't translate numeric entities.
I added an answer to the suggested duplicate How to decode numeric HTML entities in PHP
str_replace(array('”', '”'), '', $thestring);
Here is a working example: http://codepad.org/gXrZcxaF
Does this do what you're looking for:
http://shiflett.org/blog/2005/oct/convert-smart-quotes-with-php Converting smart quotes and other characters with PHP so they display correctly
http://ca2.php.net/manual/en/function.htmlentities.php#84612 Dealing with Numeric entities in PHP (comment on the manual)

Categories