Jump to content

trim off first line from string?


kev@num

Recommended Posts

hello, i have MySQL version 4.1.11, PHP Version: 4.4.6...

 

anyway, i have a stored in mysql paragraphs like this:-

 

Double Zero - Rythm Beater / Immaculate Conception

 

Double Zero strike back (just like the Empire did) with some sleazy Jump Up funk, imagine immersing yourself in a tub full of pheromones before donning a proper pimp suit and going out on the pull. Well that’s precisely what ‘Rhythm Beater’ has done, and it’s got hyped up ladies literally dripping off it. ‘Immaculate Conception’ must be what they told the aforementioned women’s fathers… anyway, it’s jammed full of more sexual chemistry that’ll make any self respecting Lady Junglist get her knickers in a knot. Nice

 

i need the data in mysql to stay like this, however sometimes when i retreive the information i would like to ignore the first line (the title) and just show the paragraph.. does this sound like something that's possible?

 

at the moment, i'm pulling the data like this:

 

$query_Recordset2 = sprintf("select products_description from products_description where products_id = %s", $colname_Recordset2);

 

and then shortening the paragraph to 350 characters like this:

 

function shorten( $str, $num = 350 ) {
  if( strlen( $str ) > $num ) $str = substr( $str, 0, $num ) . "...";
  return $str;
} 

 

does anyone know the best way, if at all that i can trim off the first line? either by the mysql select statement or the php function shorten?

 

thanks in advance :)

kev.

 

oh ps, i also use this function to convert the line breaks into readable format:

 

function nl2brStrict($text, $replacement = '')
{
    return preg_replace("((\r)+)", trim($replacement), $text);
   //  return preg_replace("((\r\n)+)", trim($replacement), $text);
}

Link to comment
Share on other sites

Sure, explode by the new line:

 

<?php
$str = 'Double Zero - Rythm Beater / Immaculate Conception

Double Zero strike back (just like the Empire did) with some sleazy Jump Up funk, imagine immersing yourself in a tub full of pheromones before donning a proper pimp suit and going out on the pull. Well that’s precisely what ‘Rhythm Beater’ has done, and it’s got hyped up ladies literally dripping off it. ‘Immaculate Conception’ must be what they told the aforementioned women’s fathers… anyway, it’s jammed full of more sexual chemistry that’ll make any self respecting Lady Junglist get her knickers in a knot. Nice';

list($title,$blank_line,$content) = explode("\n",$str);
echo $content;
?>

 

$title would have the title in, $blankline is just a placeholder if you like, since there is a blank line.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.