-2

I have a PHP code that actually load the data from a form and then save it as a XML file. It´s needed to setup a rule where accentuation and lowercasse characters are not allowed in the form. In order words, the output XML file attributes elements field need to be filled with UPPERCASE and can NOT BE ACCENTUATED.

Is there a way to set this "rule" into my PHP code??

Even if the final user input lowercase characters and/or accentuation?

Eg. User Input (form field called Name/Address):

Name: John

Address: Ratão

File Output:

<attribute domainname="Name">JOHN</attribute>

<attribute domainname="Address">RATAO</attribute>

PHP Code: (Actual)

    $domElement = $domDocument->createElement('attribute', $posted_data['name']);
    $domAttribute = $domDocument->createAttribute('domainname');
    $domAttribute->value = 'Name';

    $domElement = $domDocument->createElement('attribute', $posted_data['address']);
    $domAttribute = $domDocument->createAttribute('domainname');
    $domAttribute->value = 'Address';
Blue
  • 22,608
  • 7
  • 62
  • 92
Wagner
  • 34
  • 9
  • Possible duplicate - https://stackoverflow.com/a/32562697 – IVO GELOV Jul 18 '18 at 14:05
  • 1
    Please do not vandalize your posts. By posting on the Stack Exchange network, you've granted a non-revocable right for SE to distribute that content (under the [CC BY-SA 3.0 license](https://creativecommons.org/licenses/by-sa/3.0/)). By SE policy, any vandalism will be reverted. – Blue Aug 06 '18 at 15:44

1 Answers1

1

You can use strtoupper and iconv.

// get the value
$value = isset($_POST['nameOfField']) ? $_POST['nameOfField'] : '';
// set the locale
setlocale(LC_ALL, "en_US.utf8");  
// replace accents
$value = iconv('UTF-8','ASCII//TRANSLIT',$value);
//make upper case
$value = strtoupper($value);

More on replacing accents in string: Replacing accented characters php

Florian
  • 725
  • 6
  • 27