Challenge the best message of the source code (iv) _php Foundation

Source: Internet
Author: User
Tags error handling strlen
config.php file

<?php
Your username and password, as well as the database name, and table name, defined here once!!!
Because the user name and password is afraid to be seen through the browser, so use the extension of PHP, so through browsing can not see the!!!.

$username = ' your_name '; User name
$password = ' Your_password '; Password

$hostname = ' localhost '; Host name, generally all for localhost

$db _name= ' Your_db_name '; Database name
$table _name= ' your_liuyan_table '; The name of the table that holds the message

$table _name_control= ' your_control_table '; Control Table Name

$number _records_to_display=5; The number of message bars per page!


$hang _zifu_number=50; The number of line characters to wrap!



Connect to the database, here!!!

$id _link= @mysql_connect ($hostname, $username, $password);
if (! $id _link) {
Affy_message ("The connection to the local dtabase has failed.");}

Processing parameters, all subsequent parameters can be obtained by $arr _request[' name ', whether post or get!!!

$arr _request=array ();
if (count ($HTTP _get_vars)) {
while (list ($key, $value) =each ($HTTP _get_vars)) {
$arr _request[strtolower ($key)]= $value;
}
}

if (count ($HTTP _post_vars)) {
while (list ($key, $value) =each ($HTTP _post_vars)) {
$arr _request[strtolower ($key)]= $value;
}
}

Some error handling functions!

function Affy_footer () {
Echo ' </body>}

function Affy_header ($title) {
Echo ' echo "$title";
Echo ' </title>}

function Affy_message ($msg) {
Echo ' <table> ';
Echo ' <tr><td> ';
echo "$msg";
Echo ' </td></tr> ';
Echo ' </table> ';
}

function Affy_error_exit ($msg) {
$errno = Mysql_errno ();
$error = Mysql_error ();
Echo ' Echo $msg;
echo "<br>error: ($errno) $error <br>";
Echo ' </body>Exit ();
}

Some message processing functions!!!



$test = "2123.1.45.189";

function Ip_question ($msg)
{
Echo $msg;
echo "<br>";
$ip =preg_split ("/./", $msg);
$num =count ($IP);
Echo $num;
$result = "";
For ($i =0 $i < $num-1; $i + +)
{$result = $result. $ip [$i]. ".";
echo $ip [$i];
echo "<br>";

}
$result = $result. " XX ";
return ($result);
}

$result =ip_question ($test);
echo $result;



function Add_blankto50 ($msg, $hang _zifu_number)
{
$num =strlen ($msg);

$num _need= $hang _zifu_number-$num;
$str _suffix= "";
for ($i =0; $i < $num _need; $i + +)
{
$str _suffix= $str _suffix. " ";

}
$num 6=strlen ($str _suffix);
echo $num 6;
echo "<br>";

$pattern = '/^ (. *)/';
$replacement = "\1$str_suffix";

$msg =preg_replace ($pattern, $replacement, $msg);

return ($MSG);

}

function Check_en_num ($msg)
{
$pattern = '/[x00-x7f]/';

Preg_match_all ($pattern, $msg, $matches);

$num 2=count ($matches [0]);

Return ($num 2%2);

}

function Short_one ($msg)
{
$pattern = '/.$/';
$replacement = ';
$result =preg_replace ($pattern, $replacement, $msg);

return ($result);




}

function Pian_question ($msg)
{
$pattern = "/'/";
$replacement = "'";
$temp =preg_replace ($pattern, $replacement, $msg);

$pattern = "/\ '/";
$replacement = "'";
$result =preg_replace ($pattern, $replacement, $temp);

return ($result);

}

function Check_last ($msg)
{

$pattern = '/.$/';

Preg_match ($pattern, $msg, $match);


if ($match [0]> ' ~ ')
return (1);
Else
return (0); echo "English";


}

$num 5=short_one ($test);
echo $num 5;




function Computer_message ($msg, $hang _zifu_number)
{
$msg =pian_question ($msg);

$arr _phone=preg_split ("/n/", $msg);


$num =count ($arr _phone);
Echo $num;
echo "<br>";
$num 2=strlen ($arr _phone[0]);
echo $num 2;
$first _line=1;

for ($i =0; $i < $num; $i + +)
{
while ($str _num=strlen ($arr _phone[$i]) > $hang _zifu_number)
{

$first _line=0;
$workstr = $arr _phone[$i];



$pattern _pre50= "/. {". $hang _zifu_number."} /";

Preg_match_all ($pattern _pre50, $workstr, $matches);
$temp = $matches [0][0];

if ((Check_last ($temp) ==1) and (Check_en_num ($temp) ==1))/Ji Shu and Chinese
{
$hang _zifu_shortone= $hang _zifu_number-1;

$pattern _replace= "/^. {". $hang _zifu_shortone."} /";

$replacement = ';
$arr _phone[$i]=preg_replace ($pattern _replace, $replacement, $WORKSTR);
The front 49 finishes!

$temp =short_one ($temp); Subtract one from 50.

}




Else
{

$pattern _replace= "/^. {". $hang _zifu_number."} /";

$replacement = ';
$arr _phone[$i]=preg_replace ($pattern _replace, $replacement, $WORKSTR);

}


$message = $message. $temp. " <br> ";

}

if ($first _line==1) and (strlen ($arr _phone[$i)) < $hang _zifu_number))
{

$first _line=0;
$temp _addblank= $arr _phone[$i];

$temp _addblank=add_blankto50 ($temp _addblank, $hang _zifu_number);

$message = $temp _addblank. " <br> ";

}

Else

$message = $message. $arr _phone[$i]. " <br> ";


}
return ($message);


}

$num 1=strlen ($test);
echo $num 1;
Echo $test;

echo "<br>";
$mes =add_blankto50 ($test);
$num 9=strlen ($mes);
echo $num 9;
$result =ip_question ($test);
Computer_message ($test);
echo $result;


function Checkpass ($passwd, $action, $db _name, $table _name_control, $id _link)
{



if ($action = "Delete")
$str _sql= "Select value from $table _name_control where leibie= ' delete ';";
else if ($action = "Huifu")
$str _sql= "Select value from $table _name_control where leibie= ' Huifu ';";
Else
echo "Error";



$result =mysql_db_query ($db _name, $str _sql, $id _link);

if (! $result) {
Affy_error_exit (' SQL Execution has failed. ');}


$record = Mysql_fetch_object ($result);
Echo $record->value;
echo "<br>";
Echo $passwd;
echo "<br>";
if ($record->value== $passwd)
return (1);
Else
return (0);



}

$msg =computer_message ($test, $hang _zifu_number);

Echo $msg;

?>


"This article copyright belongs to the author and the Osso net jointly owns, if needs to reprint, please indicate the author and the origin"


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.