0

这是我的问题。

我使用 Doctrine 1.2 从数据库中获取数据并将数据放入文本框中。

数据为 19" x 12" 放入文本框

结果如下:

<input type="text" value="19" x 12"" />

我想我需要逃避所有的“与\”

我的问题是:如何在不进入所有脚本并制作 str_replace() 的情况下自动执行此操作?

感谢大家。

4

3 回答 3

1

我会用htmlentities

$string = htmlentities($text_with_quotes, ENT_QUOTES);
echo '<input type="text" value="' . $string . '">';

应该给你你需要的。

于 2011-05-30T14:05:43.513 回答
0

看看htmlspecialchars,应该可以解决问题。

于 2011-05-30T14:04:53.547 回答
0

您可以在模型类中编写函数,例如:

public function getInputValue() {
    return addslashes($this->_get('table_field_name'));
}

然后在您的视图中使用。或者您可以覆盖从具体表字段获取数据的函数:

public function getFieldname() {
    return addslashes($this->_get('table_field_name'));
}

addlashes 可以替换为您想要在视图中获取实际需要的数据的任何内容。

于 2011-05-30T14:06:37.000 回答