I am trying to cut text from a database off if <!-- break -->
is found then only show what is before the break. I currently have this code
//get the description before the more link
$project_blurb = htmlspecialchars_decode($project_data['p_desc']);
if (strstr($project_blurb, '<!-- break -->')) {
$project_blurb = explode("<!-- break -->" , $project_blurb);
$project_desc = $project_blurb[0];
}
else{
$project_desc = $project_blurb;
}
This works except that the text starts with a <p>
tag and currently I'm cutting it off the ending </p>
tag which is breaking the html on the site. I want to know if there is a better way to only get the description before the "break". I've tried to us strip_tags but this also strips the comment that I need to search for and creates some ugly formatting.
Thanks
If you need to select up to your break, call strip tags after you get the field. Also, you can make it a little more efficient by only searching for your break once:
Instead of putting a special comment in your text, consider defining a maximum length for your description, so you don't have to search the string. This will be much more efficient and won't require you to modify your input.
If you are going to link to the full-text from your page, instead of expanding it in place, you could also consider letting your database do some of the work for you. Assuming you are using MySQL, you could use
LEFT(p_desc, 200)
to pull only the first 200 characters of the database from the p_desc field.