Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hello
I'm a PHP code to C # Converter can someone do that?

<center>
<form method="post"> 
<br />
<textarea id="url" name="url_form" cols="40" rows="8" style="width: 400px">
</textarea >
<br />
<input type="submit" style="margin-top: 5px; font-size: 18px" value="Check" />
</form>
</center>

<?php

if($_REQUEST['url_form']) {
$urls = trim($_POST['url_form']);
$urls = explode("\n", $urls);
$urls = array_filter($urls, 'trim');
}

if(!$urls) {
	exit;
}

?>

<div style="margin: auto; width: 50%; min-width: 400px">
<table width="500" cellpadding="5" cellspacing="5">
    <thead style="text-align: left">
        <tr>
            <th>ID</th>
            <th>URL</th>
            <th>DA</th>
            <th>PA</th>
            <th>MR</th>
            <th>EL</th>
        </tr>
    </thead>
    <tbody>

<?php

$check_count = 0;
$urls_metrics = array();

$chunked_verified_urls = array_chunk($urls,80);

foreach($chunked_verified_urls as $chunk_section) {
	
	sleep(2);
	unset($url);
	$url = $chunk_section;

	$seomoz_metrics = getSeomozMetrics($url);
	
	if($seomoz_metrics['error'] != '') {
		echo "Error[SEOMoz]: ".$seomoz_metrics['error']."<br>";
	} else {
		foreach($seomoz_metrics as $index => $seomoz_metric) {
			
			$url_metrics['pa'] = number_format($seomoz_metric['pa'], 0, '.', '');
			$url_metrics['url'] = $seomoz_metric['url'];
			$url_metrics['da'] = number_format($seomoz_metric['da'], 0, '.', '');
			$url_metrics['title'] = $seomoz_metric['title'];
			$url_metrics['external_links'] = $seomoz_metric['external_links'];
			$url_metrics['mozrank'] = number_format($seomoz_metric['mozrank'], 2, '.', '');
			$check_count  ;
			
			echo "<tr><td>";
				echo $check_count;
			echo "</td><td>";
				echo str_replace("http://","",$url_metrics['url']);
			echo "</td><td>";
				echo $url_metrics['da'];
			echo "</td><td>";
				echo $url_metrics['pa'];
			echo "</td><td>";
				echo $url_metrics['mozrank'];
			echo "</td><td>";
				echo $url_metrics['external_links'];
			echo "</td>";
			echo "</tr>";

			$urls_metrics[] = $url_metrics;
        }
	}
}
?>

</tbody></table>

</div>

<?php

function getSeomozMetrics($objectURL) {
		
		$accessID = "accessID";
		
		$secretKey = "secretKey";
	
		$expires = time()   600;

		$stringToSign = $accessID."\n".$expires;
		 
		$binarySignature = hash_hmac('sha1', $stringToSign, $secretKey, true);
		
		$urlSafeSignature = urlencode(base64_encode($binarySignature));	 
	
		$cols = 68719476736 34359738368 536870912 32768 16384 2048 32 4;
		 
		$requestUrl = "http://lsapi.seomoz.com/linkscape/url-metrics/?Cols=".$cols."&AccessID=".$accessID."&Expires=".$expires."&Signature=".$urlSafeSignature;
		 
		$batchedDomains = $objectURL;
		$encodedDomains = json_encode($batchedDomains);
	
		$options = array(
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_POSTFIELDS     => $encodedDomains
			);
		 
		$ch = curl_init($requestUrl);
		curl_setopt_array($ch, $options);
		$content = curl_exec($ch);
		curl_close( $ch );
		 
		$response = json_decode($content,true);
		
		$count = 0;

    if (isset($response['error_message'])) {
        $metric_list = array('error'=>$response['error_message']);
    } else {
	
        foreach($response as $site_metric) {
			
			$metric_list[$count]['url'] = $objectURL[$count];
			$metric_list[$count]['subdomain'] = $site_metric['ufq'];
           $metric_list[$count]['domain'] = $site_metric['upl'];
           $metric_list[$count]['pa'] = $site_metric['upa'];
           $metric_list[$count]['da'] = $site_metric['pda'];
           $metric_list[$count]['mozrank'] = $site_metric['umrp'];
           $metric_list[$count]['title'] = $site_metric['ut'];
           $metric_list[$count]['external_links'] = $site_metric['ueid'];
			$count  ;  
        }
    }
	return $metric_list;	
}

?>


What I have tried:

Hello
I'm a PHP code to C # Converter can someone do that?

<center>
<form method="post"> 
<br />
<textarea id="url" name="url_form" cols="40" rows="8" style="width: 400px">
</textarea >
<br />
<input type="submit" style="margin-top: 5px; font-size: 18px" value="Check" />
</form>
</center>

<?php

if($_REQUEST['url_form']) {
$urls = trim($_POST['url_form']);
$urls = explode("\n", $urls);
$urls = array_filter($urls, 'trim');
}

if(!$urls) {
	exit;
}

?>

<div style="margin: auto; width: 50%; min-width: 400px">
<table width="500" cellpadding="5" cellspacing="5">
    <thead style="text-align: left">
        <tr>
            <th>ID</th>
            <th>URL</th>
            <th>DA</th>
            <th>PA</th>
            <th>MR</th>
            <th>EL</th>
        </tr>
    </thead>
    <tbody>

<?php

$check_count = 0;
$urls_metrics = array();

$chunked_verified_urls = array_chunk($urls,80);

foreach($chunked_verified_urls as $chunk_section) {
	
	sleep(2);
	unset($url);
	$url = $chunk_section;

	$seomoz_metrics = getSeomozMetrics($url);
	
	if($seomoz_metrics['error'] != '') {
		echo "Error[SEOMoz]: ".$seomoz_metrics['error']."<br>";
	} else {
		foreach($seomoz_metrics as $index => $seomoz_metric) {
			
			$url_metrics['pa'] = number_format($seomoz_metric['pa'], 0, '.', '');
			$url_metrics['url'] = $seomoz_metric['url'];
			$url_metrics['da'] = number_format($seomoz_metric['da'], 0, '.', '');
			$url_metrics['title'] = $seomoz_metric['title'];
			$url_metrics['external_links'] = $seomoz_metric['external_links'];
			$url_metrics['mozrank'] = number_format($seomoz_metric['mozrank'], 2, '.', '');
			$check_count  ;
			
			echo "<tr><td>";
				echo $check_count;
			echo "</td><td>";
				echo str_replace("http://","",$url_metrics['url']);
			echo "</td><td>";
				echo $url_metrics['da'];
			echo "</td><td>";
				echo $url_metrics['pa'];
			echo "</td><td>";
				echo $url_metrics['mozrank'];
			echo "</td><td>";
				echo $url_metrics['external_links'];
			echo "</td>";
			echo "</tr>";

			$urls_metrics[] = $url_metrics;
        }
	}
}
?>

</tbody></table>

</div>

<?php

function getSeomozMetrics($objectURL) {
		
		$accessID = "accessID";
		
		$secretKey = "secretKey";
	
		$expires = time()   600;

		$stringToSign = $accessID."\n".$expires;
		 
		$binarySignature = hash_hmac('sha1', $stringToSign, $secretKey, true);
		
		$urlSafeSignature = urlencode(base64_encode($binarySignature));	 
	
		$cols = 68719476736 34359738368 536870912 32768 16384 2048 32 4;
		 
		$requestUrl = "http://lsapi.seomoz.com/linkscape/url-metrics/?Cols=".$cols."&AccessID=".$accessID."&Expires=".$expires."&Signature=".$urlSafeSignature;
		 
		$batchedDomains = $objectURL;
		$encodedDomains = json_encode($batchedDomains);
	
		$options = array(
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_POSTFIELDS     => $encodedDomains
			);
		 
		$ch = curl_init($requestUrl);
		curl_setopt_array($ch, $options);
		$content = curl_exec($ch);
		curl_close( $ch );
		 
		$response = json_decode($content,true);
		
		$count = 0;

    if (isset($response['error_message'])) {
        $metric_list = array('error'=>$response['error_message']);
    } else {
	
        foreach($response as $site_metric) {
			
			$metric_list[$count]['url'] = $objectURL[$count];
			$metric_list[$count]['subdomain'] = $site_metric['ufq'];
           $metric_list[$count]['domain'] = $site_metric['upl'];
           $metric_list[$count]['pa'] = $site_metric['upa'];
           $metric_list[$count]['da'] = $site_metric['pda'];
           $metric_list[$count]['mozrank'] = $site_metric['umrp'];
           $metric_list[$count]['title'] = $site_metric['ut'];
           $metric_list[$count]['external_links'] = $site_metric['ueid'];
			$count  ;  
        }
    }
	return $metric_list;	
}

?>
Posted
Updated 23-Mar-17 21:55pm
v5
Comments
ZurdoDev 23-Mar-17 12:43pm    
What?
[no name] 23-Mar-17 12:51pm    
"I'm a PHP code to C # Converter", you are? Then you should have no trouble with this. We are not a code translation service though.

You're going to have to rewrite this as a ASP.NET or ASP.NET/MVC application yourself. There is no conversion tool and a bunch of volunteers are not in the business of doing your work for you.
 
Share this answer
 
I don't know there is any tools or online website which can convert php code to C#.
You have only two option left to accomplish your task either learn C# or hire someone who knows C# to write completed php code in C# for you.
 
Share this answer
 
Comments
mostafa076 24-Mar-17 6:58am    
Well, no one was translated into code?
Well, no one was translated into code?
 
Share this answer
 
Comments
Richard Deeming 24-Mar-17 11:02am    
1) DO NOT post a comment as a "solution".

2) As you've already been told, YOU need to rewrite the code. Nobody here is going to do your job for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900