Archive for May, 2009

How to display certain number of words from a record?

Posted by 15 May, 2009 (0) Comment

I got good php tutorial to display certain number of words from database; in place of Database record you can use any other regular string.

<?php
$text = $row_recap['text'];
if (strlen($text) > 300) {
$ext = "... <a href='readmore.php'>read more</a>";
} else {
$ext = "";
}
function elliStr($s,$n) {
for ( $x = 0; $x < strlen($s); $x++ ) {
$o = ($n+$x >= strlen($s)? $s : ($s{$n+$x} == " "?
substr($s,0,$n+$x) . "..." : ""));
if ( $o!= "" ) { return $o; }
}
}
 
echo (elliStr("$text", 300)) . $ext;
?>
Share
Categories : Easy PHP Tags :

How to remove HTML Tags from string?

Posted by 15 May, 2009 (5) Comment

If your strings have image code, any html code or DIV code you can easily remove using this code.

<?Php
$str = preg_replace("/<.*?>/", "", $str);
?>

Hope this little code will be useful for you.

Share
Categories : Easy PHP Tags :

How to display limited characters?

Posted by 15 May, 2009 (0) Comment

To display limited characters from database or from string there is a ready made function available in php it is called – substr ( string string, int start [, int length])

<?php
$mysite = "phpmind.com";
$string = substr($mysite, 0,7);
echo $string;
?>

Out put will be – phpmind

Share
Categories : Easy PHP Tags :

How to display random record with PHP AND MYSQL?

Posted by 15 May, 2009 (0) Comment

Here is very simple way to display random records from MYSQL using PHP.

View Code MYSQL
SELECT * FROM TableName ORDER BY RAND() LIMIT 0,1
Share
Categories : Easy PHP Tags :