[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

PHP to Coldfusion

Posted on 2006-07-13
9
Medium Priority
?
234 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 2000 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
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
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…
Suggested Courses

656 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