NameSilo

PHP "Read More" link?

Spaceship Spaceship
Watch

linker

Established Member
Impact
26
Hi all,

I am looking for some PHP code that will allow me to break up an article so I only display the first paragraph or so, and add a "Read More" link that will take the reader to a new page to read the entire article.

Anyone have a script or a link to a tutorial?

Thanks!!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Use this,

PHP:
<?php

function Cont_String($string, $length, $pattern)
{
	if(strlen($string) > $length)
	{

		$final = substr("" . $string . "", 0, $length);
    
		$final .= "" . $pattern . "";

		$final. = " <a href=\"link\">More</a>";

	return $final;

	}
}

?>

It's not the best code, but it works.

The use...

PHP:
<?php

$about = "Hello, my name is Adrian bla dfhootgfgth";

    $display = Cont_String($about, 21, "...");

echo $display;

?>

That would only display 21 letters.
eg... "Hello, my name is Adr… More"
 
1
•••
Awesome, thanks!!!

Just what I was looking for!
 
0
•••
untested. but you will get the point.


PHP:
[CODE]
<?php

$sql=@mysql_query("select var1, var2, var3  from tablename ");
 if(!$sql)
 {
	die('Can not perform query!');
 }

while ( $row = @mysql_fetch_array($sql) )
  {      
		
	 $var1=strip_tags(stripslashes($row['var1']));
	 $var2=substr(strip_tags(stripslashes($row['var2'])),0,150);
	 $var3=$row['var3'];

// substr in this case takes first 150 chars from 
//the var2 (in this case some text)
  
}

  echo ('' .$var1 .'');
  echo(''.$var2.'');
  echo (' <a href="news.php?readmore='.$var3.'"> Full Paper </a>');

//var1 news name
//var2 news text (the first 150 chars we extracted before)
//var3 news id , we have to pass it to the next page

?>

[/CODE]
 
1
•••
Thanks!

More great code, this works perfectly...

:bingo:
 
0
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back