Easy PHP

How to Stop SQL Injection in MYSQL?

Posted by om 9 August, 2009 (2) Comment

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;
 
}
 
?>
  • Share/Bookmark
Categories : Easy PHP,MySQL,PHP Tags :

How to Redirect with PHP?

Posted by om 31 July, 2009 (0) Comment

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/' ) ;
?>
  • Share/Bookmark
Categories : Easy PHP Tags :

How to display certain number of words from a record?

Posted by om 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/Bookmark
Categories : Easy PHP Tags :

How to remove HTML Tags from string?

Posted by om 15 May, 2009 (3) 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/Bookmark
Categories : Easy PHP Tags :

How to display limited characters?

Posted by om 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/Bookmark
Categories : Easy PHP Tags :

How to display random record with PHP AND MYSQL?

Posted by om 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/Bookmark
Categories : Easy PHP Tags :