Need php snippet converted to

St_Aug_Beach_Bum used Ask the Experts™
I deliver content to other websites through a small php snippet.  I have other webmasters put this on their site:

//code for the Clock

I have request from users that would like to have that in #C code.  Can you convert it?

Also (I don't know anything about other than it's server side for windows), does #C work on any host, or does the #C mean it only works on #C hosts? Probably a stupid question, but I just don't know these things...

Thanks for any help,  Chris
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I'm amazed that can't do this themselves... But, something along the lines the following:

FYI :) - C# Server variables and PHP ones:
Request.ServerVariables(SERVER_NAME); same as $_SERVER["HTTP_HOST"];
Request.ServerVariables(SCRIPT_NAME); same as $_SERVER["PHP_SELF"];
Request.ServerVariables(HTTP_USER_AGENT); same as $_SERVER["HTTP_USER_AGENT"];
Request.ServerVariables(REMOTE_ADDR); same as $_SERVER["REMOTE_ADDR"];
Request.ServerVariables(HTTP_REFERER); same as $_SERVER["HTTP_REFERER"];

call the function below like (or into a var if they want they will know what to do);

string host = Request.ServerVariables(SERVER_NAME); same as $_SERVER["HTTP_HOST"];
string self = Request.ServerVariables(SCRIPT_NAME); same as $_SERVER["PHP_SELF"];
string rqst =host+self;
string url =""+rqst;

Now for the function...
        string GetContent( string url)
            string result = "Error communicating with server";
            System.Net.HttpWebRequest wreq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
            wreq.Method = "GET";
            wreq.Timeout = 3000;
            System.Net.HttpWebResponse wr = (System.Net.HttpWebResponse)wreq.GetResponse();
            if (wr.StatusCode == System.Net.HttpStatusCode.OK)
                System.IO.Stream s = wr.GetResponseStream();
                System.Text.Encoding enc = System.Text.Encoding.GetEncoding("utf-8");
                System.IO.StreamReader readStream = new System.IO.StreamReader( s, enc );
                result = readStream.ReadToEnd();
            return result;

Open in new window

answer to above is generally yes :)
Hi Chris
I don't do PHP and you don't do
However this is only a few lines of code I'm sure we can work this out.
Can you convert your code to an algorithm in plain English and then I'll write it in for you.
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.



Thank you all very much, sorry I didn't get back to this thread yesterday, been dealing with a sick 6 year old.

BrianMM, thank you, what I need to do, if possible (I don't know what's possible in, is have it shorter, so it's just one thing someone can easily take and cut and paste into their html (I'm trying to keep it insanely simple for them).  If having a function like that is what needs to be done though, I'll manage.

daveamour, basically all I need to do is get the url of the page the script is on (this will be $rqst).

Then fetch and display the contents of the file:

The contents of the file will be a table with the tool or data in it.

For example, the file would be something like this (we can use this as a test):

and someone should be able to fetch this file with and display it on their page.

I'm afraid thats as short as it will be in .NET, they need to include that function somewhere and then they can call it where needed. The call itself is a one-liner... but unfortinatley the code required to replicate what PHP does is as above!



Thank you, sorry it took me so long to get back and try this out and assign points, been sick as a dog with the flu.

Thank you for the help!  


were you going oink? :)


Just about!  

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial