SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Grab first line instead of number of characters

    I am trying to get the best out of a clients website by taking the keywords from their description.

    To do this I'm using:
    PHP Code:
    $stock_desc_2 stripslashes(substr(strip_tags($value['stock_desc']),0,54)); 
    54 because there room for 54 characters on the first line, which in once instance looks like this:

    HTML Code:
    James Murray, London, Domestic Regulator, c1815<BR>James Murray, London, Clockmakers Company, 1815 Listed in Bailey&rsquo;s as a maker of great repute, this domestic regulator is small and nicely understated. The eight-day movement, with anchor escapement, set in plates supported by four, large, knopped pillars. The 9-inch enamel dial inscribed &lsquo;Murray, London&rsquo; and finished with two beautifully pierced steel hands.</
    The trouble is, although my client has put a <br/> after the first sentence to create the first line, its not stopping at the first line, but picking characters out of the second line to make up the 54.

    So where I want
    HTML Code:
    James Murray, London, Domestic Regulator, c1815
    I'm actually getting:
    HTML Code:
    James Murray, London, Domestic Regulator, c1815James M
    So my question is, is there anyway to grab everything before the <br/> instead of the 54 characters that it is.

    http://www.wfbruce.co.uk/item.php?id=1000

    Cheers
    Last edited by multichild; May 16, 2011 at 04:44. Reason: Adding URL

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    array_shift(explode('<br/>',$yourinput))

    Returns the string before the first <br/> in the line. Can be nested into other functions directly.

  3. #3
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, I thought there was no chance and to my suprise, there is a way once again.

    The trouble is for me now, how do I integrate that so I can use it.

    As above, im using this to draw out the string:

    PHP Code:
    $stock_desc_2 stripslashes(substr(strip_tags($value['stock_desc']),0,54)); 
    Then calling it with echo:

    PHP Code:
    <title><? echo $stock_desc_2 ?></title>
    Would you mind helping me with this, as I am learning the trade, as my last post showed.

    Cheers again

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    Well, if you strip the tags before you try and do it, the <br/> will be gone, right? So we need to do it before we do that step....

    Hint: Inside-Out is the precedence order.

  5. #5
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got to be honest and say i have never seen the code you gave me, so will have a look and give it a go.

    But I will be back I expect...

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    We'll be here

  7. #7
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL

    Wow I bloody got it...

    Check that out.

    <SPAN STYLE= "" >James Murray, London, Domestic Regulator, c1815

    If you look in the title though the first span is still there.

    Here is my line:

    $stock_desc_2 = array_shift(explode('<BR>',stripslashes($value['stock_desc'])));

  8. #8
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm trying this, but it doesnt like it:

    PHP Code:
    $stock_desc_2 array_shift(explode('<BR>',stripslashes(substr(strip_tags($value['stock_desc']))))); 

  9. #9
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    Mhm.

    As i said, if you strip the tags first, you wont have anything to split it across...

    nested functions evaluate inside-out - meaning the first one resolved is (generally) the deepest one in the tree... you've put your functions on the surface of the tree.

  10. #10
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it sorted,

    thank you StarLion.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •