jquery查找并替换html代码的重音符号


jquery find and replace accents to html code

我正在使用PHP、jQuery和mySQL为我的网页构建一个管理站点。在本管理部分的一部分中,我使用<textarea>元素来编写几行。我是西班牙人,我使用áéíóú和ñ字母。

我正在寻找任何取代áto&aa可爱;

此外,我在将<textarea>内容发送到mySQL时仍然遇到问题。

<form action="this_file.php" method="POST">
    <textarea class="inputcat" type="text" cols="40" rows="5" name="content"></textarea>
    <input type="submit" value="upload text" name="submit">
</form>
<?php
//allow sessions to be passed so we can see if the user is logged in
session_start();
//connect to the database so we can check, edit, or insert data to our users table
$con = mysql_connect('localhost', 'user', 'pass') or die(mysql_error());
$db = mysql_select_db('dbname', $con) or die(mysql_error());
    if(isset($_POST['submit'])){
        //insert the row into the database
        $contenido = $_POST['content'];
        $SQL = "INSERT INTO table1 (`ct`) VALUE('" .$contenido. "')";//edited sytanx
        $result = mysql_query($SQL) or die(mysql_error());
    }
?>

错误为:

Unknown column 'ìmg' in 'field list'
fixed error.

最后一件事是在用户请求mysql从表中读取内容时替换áéíóú和ñletter。áéíóú在这个表中,我想在用户请求内容时实时替换

试试这个。

php

<?php
$GLOBALS['normalizeChars'] = array(
'Á'=>'&Aacute;', 'É'=>'&Eacute;', 'Í'=>'&Iacute;', 'Ó'=>'&Oacute;', 'Ú'=>'&Uacute;', 'Ñ'=>'&Ntilde', 'á'=>'&aacute;', 'é'=>'&eacute;', 'í'=>'&iacute;', 'ó'=>'&oacute;', 'ú'=>'&uacute;', 'ñ'=>'&ntilde');
function makeit($toChange){
return strtr($toChange, $GLOBALS['normalizeChars']);
}
//call makeit function before you read $row content with special characters, I mean:
$connection = mysql_connect('localhost','user','pwd') or die(mysql_error());
$db = mysql_select_db('dbname', $connection) or die(mysql_error());
$SQL = "SELECT * FROM tablename";
$result = mysql_query($SQL);
while ($row = mysql_fetch_array($result)) {
// imagine that exist a column called content with special chars
makeit($row['content']);
echo $row['content'];
}
mysql_close($connection);
?>

尝试删除您的反勾号

$SQL = "INSERT INTO table1 ('ct') VALUE('" .$contenido. "')";

并确保您的数据库是utf-8字符集