php – 从mysql插入语句中删除链接?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 从mysql插入语句中删除链接?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4406字,纯文字阅读大概需要7分钟。
内容图文
![php – 从mysql插入语句中删除链接?](/upload/InfoBanner/zyjiaocheng/904/5805ea403036446fbb85094ba5660dd5.jpg)
我想知道是否有人可以请求帮助,我正在运行MySQL插入查询,因此当用户填写表单时,它会将内容插入到数据库中.但是,我试图这样做,以便我可以删除/阻止链接(URL)插入.
我正在尝试这个,但我是MySQL的新手,我无法让它工作,我不确定我做得对,如果有人可以提供帮助,我将不胜感激.
提前致谢,
<?php ob_start(); ?>
<?php
// check if the review form has been sent
if(isset($_POST['review_content']))
if(isset($_POST['review_recipient']))
{
$content = $_POST['review_content'];
$review_recipient = $_POST['review_recipient'];
//We remove slashes depending on the configuration
if(get_magic_quotes_gpc())
{
$content = stripslashes($content);
$review_recipient = stripslashes($review_recipient);
}
//We check if all the fields are filled
if($_POST['review_content']!='')
if($_POST['review_recipient']!='')
{
{
$forbidden = array('<[\w.]+@[\w.]+>', '<\w{3,6}:(?:(?://)|(?:\\\\))[^\s]+>', '#<.*?>([^>]*)</a>#i');
$matches = array('****', '****', '****');
$post = preg_replace($forbidden, $matches, $post);
$sql = "INSERT INTO ptb_reviews (id, from_user_id, from_guest, to_user_id, content) VALUES (NULL, '-1', '".$review_recipient."', '".$profile_id."', '".$content."');";
mysql_query($sql, $connection);
$_SESSION['message']="<div class=\"infobox-wallpost\"><strong>Thank You</strong> - Your review has been sent and is awaiting approval.</div><div class=\"infobox-close4\"></div>";
header("Location: {$_SERVER['HTTP_REFERER']}");
} } } } } ?>
更新:
好吧所以我试图这样做,但它仍然允许显示网址
<?php ob_start(); ?>
<?php
// check if the review form has been sent
if(isset($_POST['review_content']))
if(isset($_POST['review_recipient']))
{
$content = $_POST['review_content'];
$review_recipient = $_POST['review_recipient'];
//We remove slashes depending on the configuration
if(get_magic_quotes_gpc())
{
$content = stripslashes($content);
$review_recipient = stripslashes($review_recipient);
$regex = "/(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w\.-]*)*\/?/";
$replacement = "[blocked url]";
$review_recipient = reg_replace($regex,$replacement,$_POST['review_recipient']);
$profile_id = intval($_POST['profile_id ']); //dont know how you get this
$content = reg_replace($regex,$replacement,$_POST['review_content']);
}
//We check if all the fields are filled
if($_POST['review_content']!='')
if($_POST['review_recipient']!='')
{
{
$sql = "INSERT INTO ptb_reviews (id, from_user_id, from_guest, to_user_id, content) VALUES (NULL, '-1', '".$review_recipient."', '".$profile_id."', '".$content."');";
mysql_query($sql, $connection);
$_SESSION['message']="<div class=\"infobox-wallpost\"><strong>Thank You</strong> - Your review has been sent and is awaiting approval.</div><div class=\"infobox-close4\"></div>";
header("Location: {$_SERVER['HTTP_REFERER']}");
} } } } } ?>
解决方法:
你遇到的问题是你在get_magic_quotes_gpc()调用中得到了正则表达式检查,Joel的代码也将reg_replace作为拼写错误,否则就行了(如果你把它放在魔术引号之外).
这是一个完全更新的脚本供您试用.
<?php
ob_start();
// check if the review form has been sent
if(isset($_POST['review_content'])) {
if(isset($_POST['review_recipient'])) {
$content = $_POST['review_content'];
$review_recipient = $_POST['review_recipient'];
//We remove slashes depending on the configuration
if(get_magic_quotes_gpc()) {
$content = stripslashes($content);
$review_recipient = stripslashes($review_recipient);
}
$regex = "/(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w\.-]*)*\/?/";
$replacement = "[blocked url]";
$review_recipient = preg_replace($regex,$replacement,$_POST['review_recipient']);
//$profile_id = intval($_POST['profile_id']); //dont know how you get this
$content = preg_replace($regex,$replacement,$_POST['review_content']);
//We check if all the fields are filled
if($_POST['review_content']!='') {
if($_POST['review_recipient']!='') {
$sql = "INSERT INTO ptb_reviews (id, from_user_id, from_guest, to_user_id, content) VALUES (NULL, '-1', '".$review_recipient."', '".$profile_id."', '".$content."');";
mysql_query($sql, $connection);
$_SESSION['message']="<div class=\"infobox-wallpost\"><strong>Thank You</strong> - Your review has been sent and is awaiting approval.</div><div class=\"infobox-close4\"></div>";
header("Location: {$_SERVER['HTTP_REFERER']}");
}
}
}
}
?>
如果你想阻止特定的单词,你也可以添加如下内容:
$regex2 = "/(.*)\b(word1|word2|word3)\b(.*)/";
$replacement2 = "[blocked word]";
然后将preg_replace更改为以下内容:
$content = preg_replace(Array($regex, $regex2),Array($replacement, $replacement2),$_POST['review_content']);
内容总结
以上是互联网集市为您收集整理的php – 从mysql插入语句中删除链接?全部内容,希望文章能够帮你解决php – 从mysql插入语句中删除链接?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。