Archive for May, 2009
How to display certain number of words from a record?
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; ?> |
How to remove HTML Tags from string?
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.
How to display limited characters?
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
How to display random record with PHP AND MYSQL?
Here is very simple way to display random records from MYSQL using PHP.

