Solved

PHP to Coldfusion

Posted on 2006-07-13
9
218 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
 

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now