我不知道是否有人可以請求幫助,我正在運行一個MySQL插入查詢,所以當用戶填寫表單時,它會將內容插入到數據庫中。但是,我試圖讓我可以刪除/阻止鏈接(URL)被插入。從mysql插入語句中刪除鏈接?
我正在嘗試這個,但是我是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.][email protected][\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']}");
} } } } } ?>
發現網址:'/(HTTPS:\/\ /()([\da-z\.-]+)\.([az\.]{2,6})([\/\w \ .-] *)* \ /?/' – 2013-05-01 11:43:05
看我的答案是,問題在於代碼的嵌套。我已經清理了一下,問題很明顯。 – naththedeveloper 2013-05-01 12:36:32