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:

$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:

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

James Murray, London, Domestic Regulator, c1815

I’m actually getting:

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.



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

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:

$stock_desc_2 = stripslashes(substr(strip_tags($value['stock_desc']),0,54));

Then calling it with echo:

<title><? echo $stock_desc_2 ?></title>

Would you mind helping me with this, as I am learning the trade, as my last post showed. :rolleyes:

Cheers again

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.

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… :smiley:

We’ll be here :wink:


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’])));

I’m trying this, but it doesnt like it:

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


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.

Got it sorted,

thank you StarLion.