分类:
2009-06-03 14:41:41
$string = “123nABC”;
echo “使用nl2br前n{$string}nn”;
$newstring = nl2br($string);
echo "使用nl2br后\n{$newstring}";
?>
使用nl2br前
123
ABC
使用nl2br后
123
ABC
$string = "I'm Lepingbeta";
echo "原字符串:{$string}\n";
$string = addslashes($string);
echo "addslashes后:{$string}\n";
$string = stripslashes($string);
echo "stripslashes后:{$string}";
?>
原字符串:I'm Lepingbeta
addslashes后:I\'m Lepingbeta
stripslashes后:I'm Lepingbeta
$string = "action=newthread&fid=72&extra=page%3D1";
//省略参数二
echo "调用parse_str前:\n";
echo "\$action = $action\n" .
"\$fid = $fid\n" .
"\$extra = $extra\n\n";
parse_str($string);
echo "调用parse_str后:\n";
echo "\$action = $action\n" .
"\$fid = $fid\n" .
"\$extra = $extra\n\n";
//不省略参数二
parse_str($string, $arr);
echo "不省略参数二,分析结果放入关联数组,数组变量为参数二\n";
print_r($arr);
?>
调用parse_str前:
$action =
$fid =
$extra =
调用parse_str后:
$action = newthread
$fid = 72
$extra = page=1
不省略参数二,分析结果放入关联数组,数组变量为参数二
Array
(
[action] => newthread
[fid] => 72
[extra] => page=1
)
$html = "phpchina.com/\" target='_blank'>PHP&China";
echo "转换前:$html\n";
//默认转换
$newhtml = htmlspecialchars($html);
echo "默认转换的结果:\n$newhtml\n\n";
//使用ENT_COMPAT
$newhtml = htmlspecialchars($html, ENT_COMPAT);
echo "使用ENT_COMPAT转换的结果:\n$newhtml\n\n";
//使用ENT_QUOTES
$newhtml = htmlspecialchars($html, ENT_QUOTES);
echo "使用ENT_QUOTES转换的结果:\n$newhtml\n\n";
//使用ENT_NOQUOTES
$newhtml = htmlspecialchars($html, ENT_NOQUOTES);
echo "使用ENT_NOQUOTES转换的结果:\n$newhtml\n\n";
?>
$html = "PHPChina
";
echo "原字符串:\n" . "$html\n\n";
$newhtml = strip_tags($html);
echo "执行strip_tags后:\n" . "$newhtml\n\n";
//使用参数二
$newhtml = strip_tags($html, ""
);
echo "使用参数二后:\n" . $newhtml;
?>
原字符串:
PHPChina
执行strip_tags后:
PHPChina
使用参数二后:
PHPChina