title: shell_exec escaping quotes in php for Twitter API --> Getting CURL to work with obscure twitter api method
body: <p>I'm using shell_exec() to execute a Twitter API Call. </p>
  
  <pre><code>shell_exec('curl -u user:password -d "id=3191321" http://api.twitter.com/1/twitterapi/twitterlist/members.xml');
  </code></pre>
  
  <p>That works fine when I authenticate correctly and put in a number for the id. </p>
  
  <p>But when I try to put in a variable ($id), it screws up.</p>
  
  <pre><code>$addtolist = shell_exec('curl -u user:pw -d "id='.$id.'" http://twitter.com/username/twitterlist/members.xml');
  </code></pre>
  
  <p>I tried flipping the quote types</p>
  
  <pre><code>$addtolist = shell_exec("curl -u user:pw -d 'id=$id' http://twitter.com/username/twitterlist/members.xml");
  </code></pre>
  
  <p>I tried using double quotes and escaping them</p>
  
  <pre><code>$addtolist = shell_exec("curl -u user:pw -d \"id=$id\" http://twitter.com/username/twitterlist/members.xml");
  </code></pre>
  
  <p>None of them worked.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>EDIT: The purists say I should be using PHP's built in curl methods, not the shell_exec. That's not working either.</p>
  
  <blockquote>
    <p>$url = '<a href="http://twitter.com/user/list/members.xml" rel="nofollow noreferrer">http://twitter.com/user/list/members.xml</a>';</p>
    
    <p>// Set up and execute the curl process</p>
    
    <p>$curl_handle = curl_init();</p>
    
    <p>curl_setopt($curl_handle, CURLOPT_URL, "$url");</p>
    
    <p>curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);</p>
    
    <p>curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);</p>
    
    <p>curl_setopt($curl_handle, CURLOPT_POST, 1);</p>
    
    <p>curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "id=$id");</p>
    
    <p>curl_setopt($curl_handle, CURLOPT_USERPWD, "user:pw");</p>
    
    <p>$buffer = curl_exec($curl_handle);</p>
    
    <p>curl_close($curl_handle);</p>
  </blockquote>
  
  <p>It returns bool(false), and doesn't properly update the Twitter List in question (the whole point of the exercise)</p>