title: pass URL special characters in XML to curl
body: <p>I had an XML file with a url variable containing special characters such as &amp;, = etc</p>
  
  <p>I have two questions:</p>
  
  <p>A. Since the special characters are not allowed in XML, how should I enter the URL? Should I encode the url and then put in XML file?</p>
  
  <p>B. Assuming that I encode the url and put it in XML file and then read in a php script. </p>
  
  <pre><code>$fxml = simplexml_load_file("mylist.xml");
  $fxml -&gt; getName();
  
  foreach($fxml-&gt;children() as $mylist)
      {
          $url = $mylist -&gt; url;
          $url = urldecode(url);
          echo $url;
  
          $feed = curl_init( $url );
          curl_setopt($feed, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($feed, CURLOPT_HEADER, 0);
          $xml = simplexml_load_string(curl_exec($feed));
  
          curl_close($feed);
          //---------------------
          //---------------------
   }
  </code></pre>
  
  <p>Here is the sample XML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;feed&gt;
          &lt;mylist&gt;
              &lt;name&gt;                                                                                                                                                                                    
               SISC                                                                                                                                                                                    
              &lt;/name&gt;
              &lt;url&gt;                                                                                                                                                                                     
               http://epubs.siam.org/action/showFeed?ui=0&amp;amp;mi=3chvf9&amp;amp;ai=s0&amp;amp;jc=sjnaam&amp;amp;type=etoc&amp;amp;feed=rss                                                                               
              &lt;/url&gt;
          &lt;/mylist&gt;
      &lt;/feed&gt;
  </code></pre>
  
  <p>Notice that I have replaced the URL in encoded form where original &amp; is replaced by its code. I also tried not using urldecode but I only get echo $url correctly.</p>
  
  <p>If I copy paste the url in curl_init($url ) under single quotes, everthing works.</p>
  
  <p>But when I encode the url and put it in XML and decode back and put it in curl_init($url ), it does not work.</p>
  
  <p>When I echo the decoded $url (see above) then I get the correct url list displayed. What am I doing wrong ?
  I read closely related posts, but could not solve this.</p>