-2

I need to place my variable $theCompany into the end of a URI for a VoiceURI on Twilio. As you can see below I've managed to create the variable but I can't figure how to put it into the URI. When we submit the page the VoiceURI field in Twilio is www.ourdomain.com/.xml.

The same is also true for the xml file I'm trying to create which saves as $theCompany.xml

The code is below, help appreciated!

Here's the line I'm using to populate the VoiceURI in Twilio:

'VoiceUrl' => "http://www.ourdomain.com/$theCompany.xml",

And here's the line I'm using to save the xml file with a new name/ same name as passed from previous into Twilio

$doc->save('"$theCompany".xml');

It's probably really simple but this isn't my normal game, I'm more on the Infusionsoft side of things but the code and web guy is on Honeymoon!

Appreciate the assistance!

--EDIT--

Thanks for the answers so far, unfortunately they don't seem to be working. Here's the full code for the PHP xml creator:

<?php
session_start();
?>
<?php

$theCompany = $_SESSION['company'];

    $doc = new DOMDocument( );
    $ele = $doc->createElement( 'Root' );
    $ele->nodeValue = 'This is a call for $_SESSION["company"] press any key to accept the call';
    $doc->appendChild( $ele );
    $doc->save("$theCompany.xml");
?>

I also need some help getting the $theCompany into the URL on the Buy Number PHP page seen below.

<?php
session_start();
?>

<?php

// this line loads the library 
require('Services/Twilio.php');

$theCompany = $_SESSION['company'];

$account_sid = 'AC7841a99c892xxxbc8f7xxx'; 
$auth_token = 'a71cxx052080xx'; 
$client = new Services_Twilio($account_sid, $auth_token); 

$phoneNumber = $client->account->incoming_phone_numbers->create(array( 
    'PhoneNumber' => $_SESSION["number"], 

    'VoiceUrl' => "http://www.ourdomain.com/"'$theCompany .'".xml", 
)); 
echo $phoneNumber->sid;
    ?>

The pages follow like so:

1) We have a PHP page to find available numbers. This page then passes the information onto the PHP page (code directly above this one) 2) That page buys the number and adds it to the account along with the VoiceURI and once submitted the page passes to the XML creator page

I have a feeling I should switch the buy and xml pages around so we search for a number then create the XML file then buy the number but not sure if that matters?

Thanks for sticking with me!

--EDIT #2--

Hi guys, sorry about this I know you're all helping best you can. I'm still having trouble with this so I'm thinking it might be best to create the XML file and pass that as a variable to the PHP file that sends info into Twilio. If we were to create the XML with $doc->save($theCompany.'.xml'); how would we pass that as a variable to the next page in place of $doc->save($theCompany.'.xml');?

I think it makes more sense to create the variables then to add them in place of the URI which is attempting to be a hybrid of static and dynamic.

So I'd be looking at something like this:

$phoneNumber = $client->account->incoming_phone_numbers->create(array( 
    'PhoneNumber' => $_SESSION["number"],                
    'VoiceUrl' => $theXML, 
)); 

Do you think that's a better option to the route I'm taking now?

user3666207
  • 29
  • 1
  • 8

3 Answers3

0

Use this

$doc->save($theCompany.".xml");
Harshit
  • 5,147
  • 9
  • 46
  • 93
0

If I haven't misunderstood, this seems like a really simple problem.

Either you can write variables in a string using double quotes, like this:

$doc->save("$theCompany.xml");

Or you use single quotes for clarity, making it easier to look at:

$doc->save($theCompany . '.xml');
0

On your first code bit you wrote this:

$ele->nodeValue = 'This is a call for $_SESSION["company"] press any key to accept the call';

You have to make sure the session variable is escaped, like this:

$ele->nodeValue = 'This is a call for ' . $_SESSION["company"] . ' press any key to accept the call';

And for your second code bit, your phoneNumber variable has to be properly escaped:

    $phoneNumber = $client->account->incoming_phone_numbers->create(array( 
        'PhoneNumber' => $_SESSION["number"], 
        'VoiceUrl' => 'http://www.ourdomain.com/' . $theCompany . '.xml', 
    ));