Character array in PHP

Discussion in 'PHP' started by vic_msn, Nov 19, 2006.

  1. #1
    is there a character array in php
    i want to display only first 100 characters in a string how can i do that i am not able to do it using arrays as i use in c/c++ .
    Also how can i search for a particular letter in a variable.
    example in http:// www. imobilecentral .be/ and www. imobilecentral . be/
    how can i search for http:// and replace if i want
     
    vic_msn, Nov 19, 2006 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    First 100 characters.
    
    $string = 'a very long string here....';
    
    echo substr($string, 0, 100);
    
    PHP:
    As for the other, you can do.
    
    
    $domain = preg_replace('/https?:\/\/', 'replace with whatever', $domain);
    
    PHP:
     
    nico_swd, Nov 19, 2006 IP
  3. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Actually, a string is an array.

    
    $string = 'a very long string here....';
    echo $string[0];
    echo $string[2];
    
    Code (markup):
    This prints "av" to the screen. In the end, you will find string manipulation is a lot easier than under C/C++ and that you can replicate all the functionality you are used to.
     
    clancey, Nov 19, 2006 IP
  4. vic_msn

    vic_msn Well-Known Member

    Messages:
    2,233
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    155
    #4
    thanks for the previous answer. i think i am asking too silly questions. i need to dust my programming books.:D
    so what is the difference between preg_replace and str_replace
     
    vic_msn, Nov 19, 2006 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    nico_swd, Nov 20, 2006 IP