Easy PHP
How to Stop SQL Injection in MYSQL?
Every PHP-MYSQL programmer need to know Anti-SQL Injection.
Please take a look at very simple function which can save your database!!
<?Php function ClearInput($dirty){ if (get_magic_quotes_gpc()) { $clean = mysql_real_escape_string(stripslashes($dirty)); }else{ $clean = mysql_real_escape_string($dirty); } return $clean; } ?> |
How to Redirect with PHP?
You need to replace the URL above with the URL you wish to direct to.
Use this simple PHP script to redirect a user from the page they entered to a different web page.
<?php header( 'Location: http://www.phpmind.com.com/blog/' ) ; ?> |
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.

