Advertisement
fruffl

php goes C#-Types&-Syntax

Sep 13th, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.28 KB | None | 0 0
  1. ================================================================================
  2. StringUnit::String
  3. ================================================================================
  4.  
  5.                                                                         php code
  6.     ============================================================================
  7.     <?PHP
  8.         $string = new String('foobar');
  9.         print $string->toString();
  10.     ?>
  11.     ============================================================================
  12.  
  13.                                                                           result
  14.                                                            generic string-object
  15.     ============================================================================
  16.     String::__set_state(array(
  17.        '__copy' => 'foobar',
  18.        '__hash' => '255c71d6',
  19.        '__buffer' => '',
  20.        '__type' =>
  21.       Type::__set_state(array(
  22.          '__type' => 'String',
  23.          '__isArray' => false,
  24.          '__isPrimitive' => true,
  25.          '__isLocked' => false,
  26.          '__isCountable' => false,
  27.          '__isIterator' => false,
  28.          '__locktrace' =>
  29.         array (
  30.         ),
  31.       )),
  32.        '__buffer' => 'foobar',
  33.     ))
  34.    
  35.     ============================================================================
  36.  
  37. ================================================================================
  38. StringUnit::trimStart
  39. ================================================================================
  40.  
  41.                                                                         php code
  42.     ============================================================================
  43.     <?PHP
  44.         $code = array
  45.         (
  46.           "using System;",
  47.           "",
  48.           "public class HelloWorld",
  49.           "{",
  50.           "   public static void Main()",
  51.           "   {",
  52.           "      // This code displays a simple greeting",
  53.           "      //   to the console.",
  54.           "      //   test:",
  55.           "      //   / ",
  56.           "      Console.WriteLine(\"Hello, World.\");",
  57.           "   }",
  58.           "}"
  59.         );
  60.     ?>
  61.     ============================================================================
  62.  
  63.                                                                         php code
  64.     ============================================================================
  65.     <?PHP
  66.         $lines = new StringArray($code);
  67.         $lines->rightJoin(new String("\n"));
  68.         foreach($lines as $line)
  69.           print $line->get();
  70.     ?>
  71.     ============================================================================
  72.  
  73.                                                                           result
  74.                                                            before strip comments
  75.     ============================================================================
  76.     using System;
  77.    
  78.     public class HelloWorld
  79.     {
  80.        public static void Main()
  81.        {
  82.           // This code displays a simple greeting
  83.           //   to the console.
  84.           //   test:
  85.           //   /
  86.           Console.WriteLine("Hello, World.");
  87.        }
  88.     }
  89.    
  90.     ============================================================================
  91.  
  92.                                                                         php code
  93.     ============================================================================
  94.     <?PHP
  95.         $comment = new String('//');
  96.         $replace = new String('/ ');
  97.        
  98.         $lines   = new StringArray($code);
  99.         $lines
  100.         ->rightJoin(new String("\n"))
  101.         ->trimStart();
  102.        
  103.         foreach($lines as $line)
  104.           if($line->startsWith($comment)->get() === true)
  105.             print $line->trimStart($replace)->get();
  106.     ?>
  107.     ============================================================================
  108.  
  109.                                                                           result
  110.                                                               extracted comments
  111.     ============================================================================
  112.     This code displays a simple greeting
  113.       to the console.
  114.       test:
  115.       /
  116.    
  117.     ============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement