cut long strings

Discussion in 'PHP' started by darkhorn, Apr 5, 2009.

  1. #1
    I want cut long strings. For example
    <?php
    $sentence = "Hello, my name is Pikachu, and I want to give you some electroshock."; //here were over 20 characters
    // cut $sentence from 10th charecter and use the firs part, throw away the second part
    echo $sentence;
    //the output will be "Hello, my "
    ?>
    PHP:
    Do you know what function I have to use for that?
     
    darkhorn, Apr 5, 2009 IP
  2. darkhorn

    darkhorn Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think this will work
    $string = substr($string,0,30);
    PHP:
     
    darkhorn, Apr 5, 2009 IP
  3. ToLynn.com

    ToLynn.com Banned

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Use this:

    $sentence = substr($sentence, 0, 10);
    PHP:
     
    ToLynn.com, Apr 5, 2009 IP
  4. darkhorn

    darkhorn Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Oh, yes. My real problem was with 290/150 characters. It was just a simple example.
     
    darkhorn, Apr 5, 2009 IP