Solved

PHP to Coldfusion

Posted on 2006-07-13
9
217 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
Comment Utility
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
Comment Utility
beware if you have debugging on the XML will never format correctly.

<cfsetting showdebugoutput="false">
0
 
LVL 18

Expert Comment

by:Plucka
Comment Utility
lostboyinsofla,

Use <cfheader instead of the php version.

Regards
Plucka
0
 

Author Comment

by:lostboyinsofla
Comment Utility
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
Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

 

Author Comment

by:lostboyinsofla
Comment Utility
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
Comment Utility
thats becuase your code isnt returning an XML doc. try putting the url in the browser.
0
 

Author Comment

by:lostboyinsofla
Comment Utility
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
Comment Utility
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
Comment Utility
No sorry I thought you re pasted my code.  That did solve me problem.  TY
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
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 Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
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…

771 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

11 Experts available now in Live!

Get 1:1 Help Now