10 Replies - 846 Views - Last Post: 06 August 2015 - 12:09 PM Rate Topic: -----

#1 imilanspinka   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 06-August 15

Could anyone convert this C# code to PHP PLEASE?

Posted 06 August 2015 - 11:17 AM

Could anyone convert this C# code to PHP PLEASE?

using System;

public class stringAnalysis
{	
	public void Main(string[] args)
	{
		string _userString = //i can get the string from within php
		AnalyseString(_userString);
	}
	
	private void AnalyseString(string userString)
	{
		string[] data = userString.Split(' ');
		bool mozillaCompatible = false;
		string referenceOS = "unknown";
		
		if(userString.StartsWith("Mozilla/5.0"))
		{
			mozillaCompatible = true;
			if(userString.StartsWith("Mozilla/5.0 (Windows NT 6.1;"))
			{
				referenceOS = "Windows 7";
			}
			else if(userString.StartsWith("Mozilla/5.0 (iPod touch; CPU iPhone OS") && userString.Contains("like Mac OS X)"))
			{
				string osV = data.GetValue(6);
				
				Console.WriteLine ("The OS version identification letter is: "+osV[0].ToString()); //echo or whatever, just a DEBUG
				Console.ReadKey(); //this is echo in a console C# app
				
				switch(osV[0])
				{
					default:
						referenceOS = "iPod Touch, iOS (version unknown)";
						break;
					case '3':
						referenceOS = "iPod Touch, iOS 3";
						break;
					case '4':
						referenceOS = "iPod Touch, iOS 4";
						break;
					case '5':
						referenceOS = "iPod Touch, iOS 5";
						break;
					case '6':
						referenceOS = "iPod Touch, iOS 6";
						break;
					case '7':
						referenceOS = "iPod Touch, iOS 7";
						break;
					case '8':
						referenceOS = "iPod Touch, iOS 8";
						break;
					case '9':
						referenceOS = "iPod Touch, iOS 9";
						break;
				}
			}
			else if(userString.StartsWith("Mozilla/5.0 (iPad; CPU iPhone OS") && userString.Contains("like Mac OS X"))
			{
				string osV = data.GetValue(5);
				
				Console.WriteLine ("The OS version identification letter is: " + osV[0].ToString()); //echo or whatever, just a DEBUG
				Console.ReadKey(); //this is echo in a console C# app
				
				switch(osV[0])
				{
					default:
						referenceOS = "iPad, iOS (version unknown)";
						break;
					case '3':
						referenceOS = "iPad, iOS 3";
						break;
					case '4':
						referenceOS = "iPad, iOS 4";
						break;
					case '5':
						referenceOS = "iPad, iOS 5";
						break;
					case '6':
						referenceOS = "iPad, iOS 6";
						break;
					case '7':
						referenceOS = "iPad, iOS 7";
						break;
					case '8':
						referenceOS = "iPad, iOS 8";
						break;
					case '9':
						referenceOS = "iPad, iOS 9";
						break;
				}
			}
			else if(userString.StartsWith("Mozilla/5.0 (iPhone; CPU iPhone OS") && userString.Contains("like Mac OS X)"))
			{
				string osV = data.GetValue(5);
				
				Console.WriteLine ("The OS version identification letter is: " + osV[0].ToString()); //echo or whatever, just a DEBUG
				Console.ReadKey(); //this is echo in a console C# app
				
				switch(osV[0])
				{
					default:
						referenceOS = "iPhone, iOS (version unknown)";
						break;
					case '3':
						referenceOS = "iPhone, iOS 3";
						break;
					case '4':
						referenceOS = "iPhone, iOS 4";
						break;
					case '5':
						referenceOS = "iPhone, iOS 5";
						break;
					case '6':
						referenceOS = "iPhone, iOS 6";
						break;
					case '7':
						referenceOS = "iPhone, iOS 7";
						break;
					case '8':
						referenceOS = "iPhone, iOS 8";
						break;
					case '9':
						referenceOS = "iPhone, iOS 9";
						break;
				}
			}
			else if(userString.StartsWith("Mozilla/5.0 (Macintosh; Intel Mac OS X"))
			{
				referenceOS = "Apple Macintosh, OS X";
			}
			else if(userString.StartsWith("Mozilla/5.0 (Linux;"))
			{
				if(userString.Contains("Android"))
				{
					referenceOS = "Android OS";
				}
				else
				{
					referenceOS = "Linux OS";
				}
			}
		}
		else
		{
			mozillaCompatible = false;
		}
		
		//I can do the other stuff in PHP
		
	}
}



I know I should not ask for code, so please if you are not gonna translate this code to PHP, just tell me, how to do
bool String.StartsWith(string value)
and
string[] data = userString.Split(' ');
in PHP. Thanks, imilanspinka

Is This A Good Question/Topic? 0
  • +

Replies To: Could anyone convert this C# code to PHP PLEASE?

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15806
  • View blog
  • Posts: 63,313
  • Joined: 12-June 08

Re: Could anyone convert this C# code to PHP PLEASE?

Posted 06 August 2015 - 11:21 AM

Quote

I know I should not ask for code,

.. then why are you asking for people to do your work for you?
Was This Post Helpful? 0
  • +
  • -

#3 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2768
  • View blog
  • Posts: 8,077
  • Joined: 15-January 14

Re: Could anyone convert this C# code to PHP PLEASE?

Posted 06 August 2015 - 11:21 AM

Start here:

http://php.net/manua...tion.strpos.php
http://php.net/manua...ion.explode.php
Was This Post Helpful? 2
  • +
  • -

#4 imilanspinka   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 06-August 15

Re: Could anyone convert this C# code to PHP PLEASE?

Posted 06 August 2015 - 11:52 AM

View Postmodi123_1, on 06 August 2015 - 11:21 AM, said:

Quote

I know I should not ask for code,

.. then why are you asking for people to do your work for you?


1. this answer was not helpful at all
2. I am not asking "Give me a code which will separate the HTTP USER AGENT string into string array with members equal to different tokens of the USER AGENT string and print the info",
I am asking how to convert certain statements from C# to PHP because until now, I only worked with C# string analysis.

Thanks for just understanding.

View PostArtificialSoldier, on 06 August 2015 - 11:21 AM, said:



Thank you, that was helpful, even though I knew the strpos function, you helped me a lot searching for the explode function (omg why is it called explode?) :D :)
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is offline

  • palpable absurdity
  • member icon

Reputation: 6905
  • View blog
  • Posts: 28,569
  • Joined: 12-December 12

Re: Could anyone convert this C# code to PHP PLEASE?

Posted 06 August 2015 - 11:57 AM

You said:

Quote

Could anyone convert this C# code to PHP PLEASE?

which is a direct request to write your code for you, and very different from

Quote

I am asking how to convert certain statements from C#

Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15806
  • View blog
  • Posts: 63,313
  • Joined: 12-June 08

Re: Could anyone convert this C# code to PHP PLEASE?

Posted 06 August 2015 - 11:58 AM

Actually, it's super helpful to me in my humanist research. Your thread title asks if anyone can convert from language a to language b... you dispense all the code you want converted, and then throw out that if no one wants to do that work the least they could do is explain two lines. You cop to knowing the rules, but forge ahead and ask for people to do the work for you. I would figure you knew the rules you would dispense with asking people to convert that giant blob of text and instead just ask about two specific lines. *shrug* People are funny that way, I guess.
Was This Post Helpful? 0
  • +
  • -

#7 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6878
  • View blog
  • Posts: 31,672
  • Joined: 10-May 07

Re: Could anyone convert this C# code to PHP PLEASE?

Posted 06 August 2015 - 12:05 PM

View Postimilanspinka, on 06 August 2015 - 02:17 PM, said:

I know I should not ask for code,

... but take my request reasonably anyway & I don't expect to be held to the rules even though I just acknowledged I'm breaking them.

Quote

1. this answer was not helpful at all


Come on....

Welcome to the site! I'm sure you'll stick around.
Was This Post Helpful? 1
  • +
  • -

#8 imilanspinka   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 06-August 15

Re: Could anyone convert this C# code to PHP PLEASE?

Posted 06 August 2015 - 12:07 PM

View Postmodi123_1, on 06 August 2015 - 11:58 AM, said:

Actually, it's super helpful to me in my humanist research. Your thread title asks if anyone can convert from language a to language b... you dispense all the code you want converted, and then throw out that if no one wants to do that work the least they could do is explain two lines. You cop to knowing the rules, but forge ahead and ask for people to do the work for you (you already said that man). I would figure you knew the rules you would dispense with asking people to convert that giant blob of text (:D) and instead just ask about two specific lines. *shrug* People are funny that way, I guess.


Okay... Any way (for me) to edit the question, so it suits the rules (but my requests as well)?

View Postno2pencil, on 06 August 2015 - 12:05 PM, said:

View Postimilanspinka, on 06 August 2015 - 02:17 PM, said:

I know I should not ask for code,

... but take my request reasonably anyway & I don't expect to be held to the rules even though I just acknowledged I'm breaking them.

Quote

1. this answer was not helpful at all


Come on....

Welcome to the site! I'm sure you'll stick around.


Yeah, yeah, I've heard (read) that many times in the last three minutes.
Was This Post Helpful? 0
  • +
  • -

#9 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15806
  • View blog
  • Posts: 63,313
  • Joined: 12-June 08

Re: Could anyone convert this C# code to PHP PLEASE?

Posted 06 August 2015 - 12:07 PM

Naw, that bell's already rung. I was just curious on the 'why' it happened that way versus another.

Spoiler



edit time
Was This Post Helpful? 0
  • +
  • -

#10 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6878
  • View blog
  • Posts: 31,672
  • Joined: 10-May 07

Re: Could anyone convert this C# code to PHP PLEASE?

Posted 06 August 2015 - 12:08 PM

Because some people just prefer to be confrontational.
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15806
  • View blog
  • Posts: 63,313
  • Joined: 12-June 08

Re: Could anyone convert this C# code to PHP PLEASE?

Posted 06 August 2015 - 12:09 PM

Ah.. so a Rick James/Couch thing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1