我传入一个字符串给这个函数:
function linkify($text) {
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_'+.~#?&//=]+)',
'<a href="''1">''1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_'+.~#?&//=]+)',
'''1<a href="http://''2">''2</a>', $text);
$text = eregi_replace('([_'.0-9a-z-]+@([0-9a-z][0-9a-z-]+'.)+[a-z]{2,3})',
'<a href="''1">''1</a>', $text);
return $text;
}
和我试图插入文本到一个字段的数据库这是一个500个字符的varchar,我得到一个错误,文本不能被插入,但当我不使用的功能,我没有得到任何错误。
任何想法?
编辑:下面是我得到的错误:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'http://sitename.com/alpha/">http:/sitename.com/alpha/' at line 1"
因此这是一个函数linkify…感谢帮助修复语法错误…看起来像是双引号vs单引号??谢谢!
根据您的错误消息,几乎可以肯定您在插入数据之前没有对数据进行转义
我假设你在这个例子中使用mysql
$value = mysql_escape_string($text);
$sql = "INSERT INTO TABLENAME (COLNAME) VALUES ('$value')";
mysql_query($sql) or die(mysql_error());