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.

PHP echo array, is there a way to limit the array echoed and...

Discussion in 'PHP' started by Stephen Wolfe, Feb 8, 2011.

  1. #1
    Hi guys,

    I am currently building a webpage that gets data from a database but then i "echo" it from the array to show my result.

    I wanted to know if anyone can help me write some code to limit the returned result (i can do it with sql, but doesn’t give the desired result) but for it to cut off the result in the last space before the limit is reached?

    any ideas?

    cheers steve
     
    Stephen Wolfe, Feb 8, 2011 IP
  2. gerulis

    gerulis Active Member

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #2
    you could print it with array_slice(); function maybe.
     
    gerulis, Feb 8, 2011 IP
  3. W3Theory

    W3Theory Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well, you can count() the items in the array, if it's less than what you want then just return the usual data, if not you can use array_splice() as mentioned above
     
    W3Theory, Feb 8, 2011 IP
  4. Stephen Wolfe

    Stephen Wolfe Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    So if my array looked like..

    array(
    [0] = 1
    [1] = my name is steve and i went to the shop
    )

    and then how say do i slice [1] down to "my name is steve"

    with the array_splice() and count i can only find examples of people adding things in.


    regards

    steve
     
    Stephen Wolfe, Feb 8, 2011 IP
  5. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #5
    In that case you will have to use substr function to chop of string at desired length.
     
    mastermunj, Feb 8, 2011 IP