0

I'm getting an array as parameter for example

$data = array ( 'name' => 'makis', 'pw' => 'sovara');

And i want to complete the below variable $nxml with the data from the array i got. 'name' and 'pw'.

        $nxml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
            <epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0
            epp-1.0.xsd">
            <command>
            <login>
            <clID>$data['name']</clID>
            <pw>$data['pw']</pw>
            <options>
            <version>1.0</version>
            <lang>en</lang>
            </options>
            <svcs>
            <objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
            <objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
            <objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
            </svcs>
            </login>
            <clTRID>nick-12345</clTRID>
            </command>
            </epp>';

What is the correct way for this cause i keep getting erros

2
  • Your esacping is not correct Commented Aug 30, 2013 at 10:41
  • ' ... <clID>'.$data['name'].'</clID> ... ' Commented Aug 30, 2013 at 10:42

7 Answers 7

2

You can try this:

$nxml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
                <epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0
                epp-1.0.xsd">
                <command>
                <login>
                <clID>'.$data['name'].'</clID> //your original code <clID>$data['name']</clID> see the difference?
                <pw>'.$data['pw'].'</pw> //same thing here
                <options>
                <version>1.0</version>
                <lang>en</lang>
                </options>
                <svcs>
                <objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
                <objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
                <objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
                </svcs>
                </login>
                <clTRID>nick-12345</clTRID>
                </command>
                </epp>';

You need to escape ' properly to make it work.

Sign up to request clarification or add additional context in comments.

Comments

1

Make it like this:

$nxml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
            <epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0
            epp-1.0.xsd">
            <command>
            <login>
            <clID>'.$data['name'].'</clID>
            <pw>'.$data['pw'].'</pw>
            <options>
            <version>1.0</version>
            <lang>en</lang>
            </options>
            <svcs>
            <objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
            <objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
            <objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
            </svcs>
            </login>
            <clTRID>nick-12345</clTRID>
            </command>
            </epp>';

Single quotes don't work in this case. if you want to display value of the variable use double quotes but that leads you to use escaping for symbols so I recommend you to use concatenation with single quotes to avoid complexity.

Comments

0
$nxml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
            <epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0
            epp-1.0.xsd">
            <command>
            <login>
            <clID>'.$data['name'].'</clID>
            <pw>'.$data['pw'].'</pw>
            <options>
            <version>1.0</version>
            <lang>en</lang>
            </options>
            <svcs>
            <objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
            <objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
            <objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
            </svcs>
            </login>
            <clTRID>nick-12345</clTRID>
            </command>
            </epp>';

Comments

0

Try like

$nxml = '....<clID>'.$data['name'].'</clID>
        <pw>'.$data['pw'].'</pw>....';

Then your entire code will be

$nxml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
        <epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0
        epp-1.0.xsd">
        <command>
        <login>
        <clID>'.$data['name'].'</clID>
        <pw>'.$data['pw'].'</pw>
        <options>
        <version>1.0</version>
        <lang>en</lang>
        </options>
        <svcs>
        <objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
        <objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
        <objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
        </svcs>
        </login>
        <clTRID>nick-12345</clTRID>
        </command>
        </epp>';

Comments

0

Try like this.Because your esacping is not correct

$data = array ( 'name' => 'makis', 'pw' => 'sovara');
 $nxml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
            <epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0
            epp-1.0.xsd">
            <command>
            <login>
            <clID>$data["name"]</clID>
            <pw>$data["pw"]</pw>
            <options>
            <version>1.0</version>
            <lang>en</lang>
            </options>
            <svcs>
            <objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
            <objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
            <objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
            </svcs>
            </login>
            <clTRID>nick-12345</clTRID>
            </command>
            </epp>';

Comments

0

try this :

<clID>"'.$data['name'].'"</clID>
<pw>"'.$data['pw'].'"</pw>

Comments

0

try this

<clID>"'.$data['name'].'"</clID>
<pw>"'.$data['pw'].'"</pw>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.