Tutorial Separate First and Last Name
$name = "John S Smith";
list($fname, $lname) = split(' ', $name,2);
echo "First Name: $fname, Last Name: $lname";
Works with or without middle name.
$name = "John S Smith";
list($fname, $lname) = split(' ', $name,2);
echo "First Name: $fname, Last Name: $lname";
Works with or without middle name.
<form action="" method="post">
<label for="name">Name:</label>
<input type="text" name="name" id="name" />
<label for="Email">Email:</label>
<input type="text" name="email" id="email" />
<label for="Message">Message:</label><br />
<textarea name="message" rows="20" cols="20" id="message"></textarea>
<input type="submit" name="submit" value="Submit" />
</form>
This could be in a seperate file (e.g. sendemail.php) in which you'd set the action URL of the form to go there. Or, have the form submit to itself (leave action URL blank) and test for one of the values of the form being POSTed and process there.
<?php
// from the form
$name = trim(strip_tags($_POST['name']));
$email = trim(strip_tags($_POST['email']));
$message = htmlentities($_POST['message']);
// set here
$subject = "Contact form submitted!";
$to = 'your@email.com';
$body = <<<HTML
$message
HTML;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
// send the email
mail($to, $subject, $body, $headers);
// redirect afterwords, if needed
header('Location: thanks.html');
?>
And make sure to keep up with security news around the web.
You'll need a TextMagic account and to download their PHP helper which they provide after signing up.
// Include the TextMagic PHP lib
require('textmagic-sms-api-php/TextMagicAPI.php');
// Set the username and password information
$username = 'myusername';
$password = 'mypassword';
// Create a new instance of TM
$router = new TextMagicAPI(array(
'username' => $username,
'password' => $password
));
// Send a text message to '999-123-4567'
$result = $router->send('Wake up!', array(9991234567), true);
// result: Result is: Array ( [messages] => Array ( [19896128] => 9991234567 ) [sent_text] => Wake up! [parts_count] => 1 )
<?php
function cleanInput($input) {
$search = array(
'@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
);
$output = preg_replace($search, '', $input);
return $output;
}
?>
Uses the function above, as well as adds slashes as to not screw up database functions.
<?php
function sanitize($input) {
if (is_array($input)) {
foreach($input as $var=>$val) {
$output[$var] = sanitize($val);
}
}
else {
if (get_magic_quotes_gpc()) {
$input = stripslashes($input);
}
$input = cleanInput($input);
$output = mysql_real_escape_string($input);
}
return $output;
}
?>
<?php
$bad_string = "Hi! <script src='http://www.evilsite.com/bad_script.js'></script> It's a good day!";
$good_string = sanitize($bad_string);
// $good_string returns "Hi! It\'s a good day!"
// Also use for getting POST/GET variables
$_POST = sanitize($_POST);
$_GET = sanitize($_GET);
?>
function mysql_get_var($query,$y=0){
$res = mysql_query($query);
$row = mysql_fetch_array($res);
mysql_free_result($res);
$rec = $row[$y];
return $rec;
}
$name = mysql_get_var("SELECT name from people where email = 'roger@freekrai.net'");
Will return the name field, so what gets returned will be "Roger" (if that was my name in the database).
function fileWrite($file, $message) {
fwrite(fopen($file, 'a'), $message . "\n");
}
function fileRead($file){
$lines = file($file);
foreach ($lines as $line_num => $line) {
echo $line, '</br>';
}
}
function randomizeFileName( $real_file_name ) {
$name_parts = @explode( ".", $real_file_name );
$ext = "";
if ( count( $name_parts ) > 0 ) {
$ext = $name_parts[count( $name_parts ) - 1];
}
return substr(md5(uniqid(rand(),1)), -16) . "." . $ext;
}