Jump to content

strlen


Dane

Recommended Posts

Hey guys,

 

Im using the peice of code below to grab the first ## characters and then add a more... for the whole thing.

 

However im using bbcode now and say for example i gets the first 170 and the end of the post looks like

 

blah blah blah[/

 

^^ it doesnt close the bold text bbcode therefore would look messy.

 

Is there a way to make it so whole strings are not broken?

 

if(strlen($website) <> 170 ) 

{ 

$totalChars = 170;

$website= substr($website,0,$totalChars)."...<a href=\"$website_feature_link/feature_more/$website_feature_id/\"><i>more</i></a>";

echo $website;

}

Link to comment
https://forums.phpfreaks.com/topic/83029-strlen/
Share on other sites

Hey.

if your capping the text at 170 characters then it will cut off what ever is the 171 and more. A way to get around this would be to see what the last 3 characters are and through an if statement check if they are == to [/i or [/b or something like that. then if they are add the extra ] to the string to close it.

Regards

mark

Link to comment
https://forums.phpfreaks.com/topic/83029-strlen/#findComment-422336
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.