Breaking at a next sentence using substr(stripslashes(trim

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hantousha
Forum Newbie
Posts: 1
Joined: Sun Jan 09, 2011 3:52 pm

Breaking at a next sentence using substr(stripslashes(trim

Post by hantousha »

I have a code see below:

Code: Select all

<b><?= stripslashes($newstitle)?></b><br><br />

<b><?= stripslashes($detrsltnewsrow['sourceagency'])?></b>&nbsp;- &nbsp;<?=$ndt?>

<br>

<?= substr(stripslashes(trim($detrsltnewsrow[news_desc])),0,701)?>

</td></tr>

<tr><td colspan="2" class="para" style="padding-left:10px;"><?= substr(stripslashes(trim($detrsltnewsrow[news_desc])),701)?></td></tr> 

It inserts the tag
</td></tr><tr><td colspan="2" class="para" style="padding-left:10px;">

at the break of the 701 character. I want it to insert this at the end of a sentence at above 701 character of a description text. The way i have it it breaks the word if it hits the 701 character in the middle of the word. Will like it to insert the tags above at the next sentence after the 701 character. Any assistance.. will be appreciated...
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Breaking at a next sentence using substr(stripslashes(tr

Post by Jade »

What you need to do is look for the first space, carriage return or punctuation mark starting from character 700. That will give you the end of the word without cutting it in the middle.
Post Reply