Solved

PHP to Coldfusion

Posted on 2006-07-13
9
223 Views
Last Modified: 2013-12-24
Can anyone show me how to write this PHP snippet in Coldfusion?

<?php
header('Content-Type: text/xml');
echo "<?xml version=\"1.0\" ?><clock1><timenow>".date('H:i:s')."</timenow></clock1>";
?>

This is what I have but it doesn't quite work:
<cfprocessingdirective suppresswhitespace="Yes">
<cfcontent type="text/xml; charset=utf-16">
<cfxml variable="xmlobject">
<clock1>
      <timenow>
            <cfoutput>#timeFormat(Now(), "hh:mm:ss tt")#</cfoutput>
      </timenow>
</clock1>
</cfxml>

<cfset myvar=toString(xmlobject)>
<cfset mynewvar=replace(myvar, "UTF-8", "utf-16")>

<cfoutput>#mynewvar#</cfoutput>
</cfprocessingdirective>


Thanks
0
Comment
Question by:lostboyinsofla
  • 4
  • 4
9 Comments
 
LVL 12

Accepted Solution

by:
mmc98dl1 earned 500 total points
ID: 17104833
This works fine for me, whats the problem or error you are encountering?

<cfsetting enablecfoutputonly="true">
<cfxml variable="xmlobject">
<cfoutput><clock1>
     <timenow>
          #timeFormat(Now(), "hh:mm:ss tt")#
     </timenow>
</clock1></cfoutput>
</cfxml>

<cfcontent type="text/xml; charset=utf-8">
<cfoutput>#xmlobject#</cfoutput>
0
 
LVL 12

Expert Comment

by:mmc98dl1
ID: 17104837
beware if you have debugging on the XML will never format correctly.

<cfsetting showdebugoutput="false">
0
 
LVL 18

Expert Comment

by:Plucka
ID: 17104864
lostboyinsofla,

Use <cfheader instead of the php version.

Regards
Plucka
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:lostboyinsofla
ID: 17104908
This is my calling template:

<html>
<head>
<title>Ajax Demonstration</title>
<style>
.displaybox {
width:150px;
background-color:#ffffff;
border:2px solid #000000;
padding:10px;
font:24px normal verdana, helvetica, arial, sans-serif;
}
</style>
<script language="JavaScript" type="text/javascript">
function getXMLHTTPRequest() {
try {
req = new XMLHttpRequest();
} catch(err1) {
  try {
  req = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (err2) {
    try {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (err3) {
      req = false;
    }
  }
}
return req;
}

var http = getXMLHTTPRequest();
 
function getServerTime() {
  var myurl = 'test.cfm';
  myRand = parseInt(Math.random()*999999999999999);
  var modurl = myurl+"?rand="+myRand;  
  http.open("GET", modurl, true);
  http.onreadystatechange = useHttpResponse;
  http.send(null);
}

function useHttpResponse() {
   if (http.readyState == 4) {
    if(http.status == 200) {
       var timeValue = http.responseXML.getElementsByTagName("timenow")[0];
       document.getElementById('showtime').innerHTML = timeValue.childNodes[0].nodeValue;
    }
  } else {
  document.getElementById('showtime').innerHTML = '<img src="../loading.gif">';
  }
}
</script>
</head>
<body style="background-color:#cccccc" onLoad="getServerTime()">
<center>
<h1>Ajax Demonstration</h1>
<h2>Getting the server time without page refresh</h2>
<form>
<input type="button" value="Get Server Time" onClick="getServerTime()">
</form>
<div id="showtime" class="displaybox"></div>
</center>
</body>
</html>



This is the code to test.cfm:
<cfprocessingdirective suppresswhitespace="Yes">
<cfcontent type="text/xml; charset=utf-16">
<cfxml variable="xmlobject">
<clock1>
      <timenow>
            <cfoutput>#timeFormat(Now(), "hh:mm:ss tt")#</cfoutput>
      </timenow>
</clock1>
</cfxml>

<cfset myvar=toString(xmlobject)>
<cfset mynewvar=replace(myvar, "UTF-8", "utf-16")>

<cfoutput>#mynewvar#</cfoutput>
</cfprocessingdirective>


The call to test.cfm doesnt' return the time however it just spins.
0
 

Author Comment

by:lostboyinsofla
ID: 17104914
When I replace test.cfm with test.php:
<?php
header('Content-Type: text/xml');
sleep(10);
echo "<?xml version=\"1.0\" ?><clock1><timenow>".date('H:i:s')."</timenow></clock1>";
?>

 It works fine and returns the time to the calling template.
0
 
LVL 12

Expert Comment

by:mmc98dl1
ID: 17104937
thats becuase your code isnt returning an XML doc. try putting the url in the browser.
0
 

Author Comment

by:lostboyinsofla
ID: 17104953
Right I understand, so back to my original question, how do I make the coldfusion template be the same as the php template?  I guess I'm assuming that you mean the php is returning an xml doc because it works correctly so how should my cf template be formatted to function the same?
0
 
LVL 12

Expert Comment

by:mmc98dl1
ID: 17104982
did you try my code from my first post?

<cfsetting enablecfoutputonly="true">
<cfxml variable="xmlobject">
<cfoutput><clock1>
     <timenow>
          #timeFormat(Now(), "hh:mm:ss tt")#
     </timenow>
</clock1></cfoutput>
</cfxml>

<cfcontent type="text/xml; charset=utf-8">
<cfoutput>#xmlobject#</cfoutput>

0
 

Author Comment

by:lostboyinsofla
ID: 17105024
No sorry I thought you re pasted my code.  That did solve me problem.  TY
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SCCM vs Windows server 5 87
Add server behaviors to Dreamweaver CC 2015 2 222
Ways to assess https/ssl websites 3 113
How do disable only TLSv1.0 in Oracle Sun One 7.1 Server 9 131
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question