0

As always, there are very similar questions on here but none quite applies to my context.

I have text coming from a textarea on a different page. I need to scan it for special characters, and assign it to a new string before inserting it into my SQL database. This was what I thought would work, but it seems to to absolutely nothing (the code still works, but the special characters remain).

$info = htmlspecialchars($_POST['info']);

The text could contain just about anything in the way of special characters (in particular, lots of üèéöàä etc.).

Paul Clift
  • 169
  • 8
  • I don't understand what it is you're trying to do and/or prevent. – Funk Forty Niner Nov 25 '18 at 14:09
  • I need special characters, such as those mentioned, to be converted to be converted to `üèéöàä` in the string.... – Paul Clift Nov 25 '18 at 14:13
  • Is there a special reason as to why you would want to insert characters like that? Are you having trouble outputting that extended character set? Are you having trouble inserting those characters? – Funk Forty Niner Nov 25 '18 at 14:14
  • I was hoping that there might be a quick and easy way of doing this, as opposed to scanning each string for each potential special character, so that when it is later used on my site, I don't get all sorts of random junk showing up. – Paul Clift Nov 25 '18 at 14:14
  • It is for a website that will be used in Switzerland; as such, users will be writing things in French, German, English and Italian. The input from users will go into a database, which will be displayed on a separate section of the site... – Paul Clift Nov 25 '18 at 14:15
  • I think this is an encoding issue. Have a look at [UTF-8 all the way through](https://stackoverflow.com/q/279170/) which I think could be a possible duplicate of the issue. – Funk Forty Niner Nov 25 '18 at 14:16
  • I thought of doing it that way, but was hoping that I could avoid the hassle and simply convert the strings directly as they come in..... – Paul Clift Nov 25 '18 at 14:18
  • You may be going about it the wrong way. If you're unable to insert an extended character set, it would be because of the collation of your database and not using the right character set on connection, that's what I think about this. – Funk Forty Niner Nov 25 '18 at 14:20
  • Yep, I think that you're right - better to focus on getting the SQL/page display into the right format. Hmm, disappointing :-) – Paul Clift Nov 25 '18 at 15:12

1 Answers1

1
htmlspecialchars() 

is used to converts some predefined characters to HTML entities. üèéöàä these are called alphabets too I guess not the predefined characters so cannot be converted into HTML entities.

Ashish Yadav
  • 1,901
  • 2
  • 17
  • 23
  • Hmm, I thought that this might be the case. Is there any kind of simple alternative that can catch characters like those I cited? Or do I have to go through and convert each one individually? – Paul Clift Nov 25 '18 at 13:59
  • I don't know if those characters can be converted to hex entities but you can filter those character with simple regex "a-z" "A-Z". This regex can be used to return all the text from lowercase to uppercase that comes between a to z. – Ashish Yadav Nov 25 '18 at 14:26
  • I was thinking of doing that, but I would ideally like to keep the characters in, and just be confident that they will always display correctly. – Paul Clift Nov 25 '18 at 15:00