PHP KNOWLEDGE SHARE
A blog for PHP Knowlegde Sharing.
Friday, 6 December 2013
What are the top 3-5 SEO areas where webmasters make the most mistakes? How can we do better on those?
What are the top 3-5 SEO areas where webmasters make the most mistakes? How can we do better on those
http://www.youtube.com/watch?v=421aTJI2Nxc
http://www.youtube.com/watch?v=421aTJI2Nxc
How do PageRank updates work?
On what basis you are increasing the PR for each PR update?
http://www.youtube.com/watch?feature=player_embedded&v=h3Jup5R1MGY
http://www.youtube.com/watch?feature=player_embedded&v=h3Jup5R1MGY
Wednesday, 27 November 2013
Voice to text & text to mp3 using google's voice speech api Webkit
followwing is the demo :
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function searchthis() {
//$('#myform').submit(); //jQuery
document.getElementById("voiceform").submit(); //normal javascript
}
</script>
</head>
<body>
<form action="" method="get" id="voiceform" >
<input type="text" name="texttoaudio" x-webkit-speech onwebkitspeechchange="searchthis()" />
</form>
<?php
if(isset($_GET['texttoaudio']))
{
$text = $_GET['texttoaudio'];
// Yes French is a beautiful language.
$lang = "en";
// Name of the MP3 file generated using the MD5 hash
// Added things to prevent bug if you want the same sentence in two different languages
$file = md5($lang."?".urlencode($text));
// Save the MP3 file in this folder with the .mp3 extension
$file = $file .".mp3";
// Verify if folder exists, if it doesn't, create it, if exists, verify CHMOD
if(!is_dir("/"))
mkdir("/");
else
if(substr(sprintf('%o', fileperms('/')), -4)!="0777")
chmod("/", 0777);
// If the MP3 file exists, do not create a new request
if (!file_exists($file))
{
// Download the content
$mp3 = file_get_contents(
'http://translate.google.com/translate_tts?ie=UTF-8&q='. urlencode($text) .'&tl='. $lang .'&total=1&idx=0&textlen=5&prev=input');
file_put_contents($file, $mp3);
}
}
?>
</body>
</html>
for more demo :
https://www.google.com/intl/en/chrome/demos/speech.html
Tuesday, 15 October 2013
Function to Avoid SQL Injection
function clean_input($input)
{
$input = trim($input);
//check to see if magic quotes are turned on
if(get_magic_quotes_gpc())
{
$input = stripslashes($input);
}
//check for numeric values, if not
//clean it
if(!is_numeric($input))
{
$input = mysql_escape_string($input);
}
return($input);
}
Function to avoid XSS (Cross Site Scripting)
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
Function To Avoid Email Injection
function spamcheck($field)
{
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail
//address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
{
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail
//address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
In the code above we use PHP filters to validate input:
- The FILTER_SANITIZE_EMAIL filter removes all illegal e-mail characters from a string
- The FILTER_VALIDATE_EMAIL filter validates value as an e-mail address
Subscribe to:
Posts (Atom)