我的数据库中的表是使用正确的UTF-8字符集创建的,如下所示:
CREATE TABLE users (
id INT NOT NULL AUTO_INCREMENT,
...
...
...
...
...
PRIMARY KEY (id)
) ENGINE = INNODB CHARACTER SET utf8 COLLATE utf8_slovak_ci;
Run Code Online (Sandbox Code Playgroud)
但是,当我使用Zend_Db_Table使用此方法从表中获取数据时:
public function getSingle($id)
{
$select = $this->select();
$where = $this->getAdapter()->quoteInto('id = ?', $id, 'INTEGER');
$select->where($where);
return $this->fetchRow($select);
}
Run Code Online (Sandbox Code Playgroud)
它返回一个带有乱糟糟的UTF-8字符的对象(我猜是转换为iso-8859-1).
当我通过phpmyadmin查看数据库时,它会正确显示所有字符,并且还显示正确的编码(UTF-8),因此我不知道问题出在哪里.
我怎么解决这个问题?
更新:
所以我做了这个,它的工作原理:
protected function _initDb()
{
$this->configuration = new Zend_Config_Ini(APPLICATION_PATH
. '/configs/application.ini',
APPLICATION_ENVIRONMENT);
$this->dbAdapter = Zend_Db::factory($this->configuration->database);
Zend_Db_Table_Abstract::setDefaultAdapter($this->dbAdapter);
$stmt = new Zend_Db_Statement_Pdo($this->dbAdapter,
"SET NAMES 'utf8'");
$stmt->execute();
}
Run Code Online (Sandbox Code Playgroud)
有更好的方法吗?
UPDATE2:
我试过这个:
protected function …Run Code Online (Sandbox Code Playgroud) 为什么这有效:
$cacheMatchesNotPlayed = $cache->load('externalData');
$cacheMatchesNotPlayed = $cacheMatchesNotPlayed['matchesNotPlayed'];
Run Code Online (Sandbox Code Playgroud)
但这不起作用:
$cacheMatchesNotPlayed = $cache->load('externalData')['matchesNotPlayed'];
Run Code Online (Sandbox Code Playgroud)
有什么理由吗?第二位更容易编写.
是否可以将Zend Framework与现有的遗留Web应用程序集成?应用程序使用所谓的意大利面条代码编写得非常糟糕(表示和应用程序逻辑之间没有分离,PHP,HTML和SQL都在一起).它是一个包含数百个页面和表单的非常大的应用程序.
现在介绍一个框架或者我们应该继续使用意大利面条代码是否有意义?使用框架重写整个应用程序是不现实的,因为它太难了.此外,我们需要为应用程序添加一些新功能,我们有一个截止日期.我们是否应该为我们需要添加的网站的所有新部分使用框架,或者我们应该按照我们之前处理它的开发人员编程的方式进行操作?
<script type="text/javascript">
//<!--
$(document).ready(function() {
$('ul.course-nav li a').each(function() {
alert(5);
if ('#' == $(this).attr('href')) {
$(this).addClass('lessOpacity');
}
});
}); //-->
</script>
Run Code Online (Sandbox Code Playgroud)
HTML当然包含搜索的元素:
<ul class="course-nav">
<li><a href="navigator.php?kam=zakladnyNahladKurzu&id=1&pos=2" class="next"><img src="css/images/16_arrow_right.png" alt="next"></a></li>
<li><a href="#" class="prev"><img src="css/images/16_arrow_left.png" alt="prev"></a></li>
<li><a href="navigator.php?kam=zakladnyNahladKurzu&id=1" class="start"><img src="css/images/16_arrow_first.png" alt="start"></a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
但它不起作用.甚至没有提醒警报.有什么建议?
首先,我的数据库使用Windows-1250作为本机字符集.我输出的数据为UTF-8.我在我的网站上使用iconv()函数将Windows-1250字符串转换为UTF-8字符串,它完美无缺.
问题是当我使用PHP DOM来解析存储在数据库中的一些HTML时(HTML是WYSIWYG编辑器的输出而且无效,它没有html,head,body标签等).
HTML可能看起来像这样,例如:
<p>Hello</p>
Run Code Online (Sandbox Code Playgroud)
这是我用来从数据库中解析某个HTML的方法:
private function ParseSlideContent($slideContent)
{
var_dump(iconv('Windows-1250', 'UTF-8', $slideContent)); // this outputs the HTML ok with all special characters
$doc = new DOMDocument('1.0', 'UTF-8');
// hack to preserve UTF-8 characters
$html = iconv('Windows-1250', 'UTF-8', $slideContent);
$doc->loadHTML('<?xml encoding="UTF-8">' . $html);
$doc->preserveWhiteSpace = false;
foreach($doc->getElementsByTagName('img') as $t) {
$path = trim($t->getAttribute('src'));
$t->setAttribute('src', '/clientarea/utils/locate-image?path=' . urlencode($path));
}
foreach ($doc->getElementsByTagName('object') as $o) {
foreach ($o->getElementsByTagName('param') as $p) {
$path = trim($p->getAttribute('value'));
$p->setAttribute('value', '/clientarea/utils/locate-flash?path=' . urlencode($path));
}
}
foreach ($doc->getElementsByTagName('embed') as …Run Code Online (Sandbox Code Playgroud) 假设我有这个页面(page.html):
<html>
<body>
<h1>AAA</h1>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
$.get('page2.html', function(data){
// I want to replace the entire HTML with the HTML of page2.html
// but this doesnt' work
$('html').replaceWith(data);
});
}); //]]>
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
另一页(page2.html):
<html>
<body>
<h1>BBB</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
正如您在我的代码段中所看到的,我想从page2.html获取HTML并使用获取的响应替换page.html的整个内容.
怎么做?
我想从0到99选择10个随机整数.我知道我可以使用:
random.randint(a, b)
Run Code Online (Sandbox Code Playgroud)
但是如何告诉randint()我只想要不同的整数.
我是否必须在每个随机生成后检查以查看是否已生成整数并再次调用该方法?这似乎不是一个最佳解决方案.
有没有更好的方法来检查文件是否存在(它在不同的域上,因此file_exists不起作用)比这个?
$fp = fsockopen($fileUri, 80, $errno, $errstr, 30);
if (!$fp) {
// file exists
}
fclose($fp);
Run Code Online (Sandbox Code Playgroud) x和y的范围是0到99.
我目前正在这样做:
excludeFromTrainingSet = []
while len(excludeFromTrainingSet) < 4000:
tempX = random.randint(0, 99)
tempY = random.randint(0, 99)
if [tempX, tempY] not in excludeFromTrainingSet:
excludeFromTrainingSet.append([tempX, tempY])
Run Code Online (Sandbox Code Playgroud)
但这需要很长时间,我真的需要加快速度.
有任何想法吗?
我正在尝试匹配看起来像这样的文件名:
45.pdf
Run Code Online (Sandbox Code Playgroud)
要么
45_2.pdf
Run Code Online (Sandbox Code Playgroud)
所以有一个正整数,一个可选的下划线,后跟另一个正整数,一个句号和一个代表一个扩展的字符串.
问题是,我的正则表达式也匹配45_.pdf,我不想这样做.
这里是:
$aRegexp = '/[0-9]+_?[0-9]*\\.[a-z]+/';
//$aString = '55.pdf';
//$aString = '55_5.pdf';
$aString = '55_.pdf';
var_dump(preg_match($aRegexp, $aString)); // should return int(0)
Run Code Online (Sandbox Code Playgroud)