...

View Full Version : Making Paragraphs A Minimum Length



discomaniac
11-16-2011, 10:39 PM
Hi

I have a database driven php website, and I am looking for a way to make the first paragraph a MINIMUM length say 550 characters including spaces. The paragraph can be longer that this but not shorter, and it is to only affect the first paragraph.

As some of our content is sourced from writers that do not follow or writing model we need a way to control this and I understand that we would need to strip all paragraph and line break tags from the first 550 characters.

Is this possible, thank you and I look forward to your replies as this one has got me stumped

myfayt
11-17-2011, 12:59 AM
You are looking for either of these.

http://php.net/manual/en/function.substr-replace.php

http://php.net/manual/en/function.substr.php

discomaniac
11-17-2011, 03:35 AM
Thank you but I do not think that these will work as from what I see none of these will display the first 550 characters and remove the paragraph and line break formatting or am I missing something.

Which one do you think would work as I do not see which one would apply.

Adee
11-17-2011, 03:54 AM
Thank you but I do not think that these will work as from what I see none of these will display the first 550 characters and remove the paragraph and line break formatting or am I missing something.

Which one do you think would work as I do not see which one would apply.


Try this.. it's lulzy but it worked for me



<?php

$str = "aocibedied aocibedied aocibedied aocibedied <p>aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied <br />aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied </p>aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied<br /> aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied <br />aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied aocibedied";

if(strlen($str) > 550)
{
$shortened = '';
for($i=0;$i<550;$i++)
{
$shortened .= $str[$i];
}

echo "Length: ". strlen($shortened) . "<br />";
$shortened = strip_tags($shortened);
echo $shortened;
}



?>

discomaniac
11-17-2011, 05:36 AM
I tried it but couldn't get it to work, here is the code that I used



<?php

$str =

$images=getImages('articles',$info['article_id']);
if($images){

;

if(strlen($str) > 550)
{
$shortened = '';
for($i=0;$i<550;$i++)
{
$shortened .= $str[$i];
}

echo "Length: ". strlen($shortened) . "<br />";
$shortened = strip_tags($shortened);
echo $shortened;
}
?>

Adee
11-17-2011, 05:52 AM
I tried it but couldn't get it to work, here is the code that I used



<?php

$str =

$images=getImages('articles',$info['article_id']);
if($images){

;

if(strlen($str) > 550)
{
$shortened = '';
for($i=0;$i<550;$i++)
{
$shortened .= $str[$i];
}

echo "Length: ". strlen($shortened) . "<br />";
$shortened = strip_tags($shortened);
echo $shortened;
}
?>

$str has to be something since its the variable that is used in the conditional......

discomaniac
11-17-2011, 07:07 AM
Thank you but the articles are stored in our database so do you know how I would work around this please?

discomaniac
11-18-2011, 08:24 AM
Any ideas please?

Adee
11-18-2011, 08:57 AM
make $str = the call to your database for an article..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum