call function php in C #

2

As by C # in WindowsFormsApplication call a function from a php page and pick up the value from it, eg:
page php:

function retornar()
{
  $valor = "aa";
  return $valor;
}

In case I would like to call this page through C # and assign a value of C # to the value that will come, in case "aa".

    
asked by anonymous 14.03.2017 / 16:04

2 answers

7

If it's a "php page" then I suppose you're talking about a web page anyway, so in practice you should call the function on your webpage, for example teste.php :

<?php

function retornar() {
  $valor = "aa";
  return $valor;
}

echo retornar();

Or it may even be just this:

<?php

echo "aa";

And then call the address http://seusite/teste.php (yourite is just an example) in your own C # , you can use #

Call in your C # file

WebClient client = new WebClient();
string downloadString = client.DownloadString("http://seusite/teste.php");

Or save content in a document:

WebClient client = new WebClient ();
client.DownloadFile("http://seusite/teste.php", " C:\conteudo.txt");
    
14.03.2017 / 16:46
0

According to what I researched, in C # you can execute whatever you want in the command line as follows:

string strCmdText;
strCmdText= "/C copy /b Image1.jpg + Archive.rar Image2.jpg";
System.Diagnostics.Process.Start("CMD.exe",strCmdText);

source: link

Since you can run commands on your PC, instead of accessing a URL you can run PHP code through the interpreter that comes with PHP5 +. It would just be the case that you run your .php file straight from the command line, hence you will not need a server running the desired program. You can even pass arguments directly to this command line, and reference them inside PHP through the $ argc (number of arguments) and $ argv (the arguments themselves, in string) objects.

php nome_do_arquivo.php argumento1 argumento2
    
14.03.2017 / 20:42