Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-16-2011, 10:39 PM   PM User | #1
discomaniac
New to the CF scene

 
Join Date: Nov 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
discomaniac is an unknown quantity at this point
Making Paragraphs A Minimum Length

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
discomaniac is offline   Reply With Quote
Old 11-17-2011, 12:59 AM   PM User | #2
myfayt
Senior Coder

 
Join Date: Apr 2010
Posts: 1,156
Thanks: 46
Thanked 95 Times in 94 Posts
myfayt can only hope to improve
You are looking for either of these.

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

http://php.net/manual/en/function.substr.php
__________________
Been a sign maker for 5 years. My business:
American Made Signs
myfayt is offline   Reply With Quote
Old 11-17-2011, 03:35 AM   PM User | #3
discomaniac
New to the CF scene

 
Join Date: Nov 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
discomaniac is an unknown quantity at this point
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.
discomaniac is offline   Reply With Quote
Old 11-17-2011, 03:54 AM   PM User | #4
Adee
Regular Coder

 
Join Date: Jul 2010
Location: Oregon City
Posts: 280
Thanks: 5
Thanked 50 Times in 49 Posts
Adee can only hope to improve
Quote:
Originally Posted by discomaniac View Post
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 Code:
<?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;
}



?>
Adee is offline   Reply With Quote
Old 11-17-2011, 05:36 AM   PM User | #5
discomaniac
New to the CF scene

 
Join Date: Nov 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
discomaniac is an unknown quantity at this point
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;
}
?>
discomaniac is offline   Reply With Quote
Old 11-17-2011, 05:52 AM   PM User | #6
Adee
Regular Coder

 
Join Date: Jul 2010
Location: Oregon City
Posts: 280
Thanks: 5
Thanked 50 Times in 49 Posts
Adee can only hope to improve
Quote:
Originally Posted by discomaniac View Post
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......
Adee is offline   Reply With Quote
Old 11-17-2011, 07:07 AM   PM User | #7
discomaniac
New to the CF scene

 
Join Date: Nov 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
discomaniac is an unknown quantity at this point
Thank you but the articles are stored in our database so do you know how I would work around this please?
discomaniac is offline   Reply With Quote
Old 11-18-2011, 08:24 AM   PM User | #8
discomaniac
New to the CF scene

 
Join Date: Nov 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
discomaniac is an unknown quantity at this point
Any ideas please?
discomaniac is offline   Reply With Quote
Old 11-18-2011, 08:57 AM   PM User | #9
Adee
Regular Coder

 
Join Date: Jul 2010
Location: Oregon City
Posts: 280
Thanks: 5
Thanked 50 Times in 49 Posts
Adee can only hope to improve
make $str = the call to your database for an article..
Adee is offline   Reply With Quote
Reply

Bookmarks

Tags
paragraph, php, script, truncate, wrap

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:03 PM.


Advertisement
Log in to turn off these ads.