Solved

PHP to Coldfusion

Posted on 2006-07-13
9
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Search on a site 5 159
How to stress test an ASP.NET https website 3 101
exchange 2010 turning off 3des ciphers 2 543
Adding multiple JVM environments to RedHat 6 7 78
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…
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …

738 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