Loading ...
Sorry, an error occurred while loading the content.

Undocumented String Access

Expand Messages
  • Day Dreamer
    Hi all, String in PHP are considered as Immutable, that means when you change a string a completely new string is created and allocated in memory. But this is
    Message 1 of 1 , Nov 2, 2004
    • 0 Attachment
      Hi all,
      String in PHP are considered as Immutable, that means when you change
      a string a completely new string is created and allocated in memory.
      But this is not 100 percent true. Here is an undocumented way to
      access string directly as well as to modify it. In this way a string
      variable could be considered as a character array.

      <?
      $str = "Hello World";
      echo $str[0]; //This will print 'H'
      $str[4] = "";
      echo $str; //This will print "Hell World" , note that 5th char is null.
      ?>


      Thanks
      --August
    Your message has been successfully submitted and would be delivered to recipients shortly.