1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Something like explode

Discussion in 'PHP' started by adresanet, Oct 2, 2005.

  1. #1
    Hi,

    If I have a var $a="over 300 words here..."; how can I obtaine 2 var $b="70 words here"; and $c="next words";
     
    adresanet, Oct 2, 2005 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    $b = implode (' ', array_slice (explode (' ', $a), 0, 70));
    PHP:
     
    digitalpoint, Oct 2, 2005 IP
  3. rickbkis

    rickbkis Peon

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This gets both strings as requested -

    $ary = explode(' ', $str300);
    $a = implode(' ', array_slice($ary, 0, 70);
    $b = implode(' ', array_slice($ary, 71);

    Assuming there was only one space between words, assuming no tabs
    separating words, etc., etc.

    It's kind of expensive, though. If performance is an issue, you might want use strpos to get to the breaking space (through a loop or some such construct), and then use substrings from the strpos return.

    rickb
     
    rickbkis, Oct 3, 2005 IP
  4. adresanet

    adresanet Peon

    Messages:
    131
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I need something to work fast. Time is a priority.
    Thanks
     
    adresanet, Oct 3, 2005 IP
  5. adresanet

    adresanet Peon

    Messages:
    131
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If someone else need it I used this:
    $b = substr($a, 0, 350);
    $c = substr($a, 350);
     
    adresanet, Oct 8, 2005 IP