为什么我的代码不起作用?这些例子之间只有一个变化。我想可能是$anchor类型的问题?
此代码无效:
<?php
header('Content-Type: text/html; charset=utf-8');
$db = mysql_connect('localhost', 'db_name', 'db_pass');
mysql_select_db('db_name');
mysql_set_charset('utf8');
$res = mysql_query("SELECT * FROM product_description");
while($row = mysql_fetch_array($res)){
$anchor = strval($row['description']); //Only this string changed!
$anchor = preg_replace(
'@\\<a\\b[^\\>]*\\>(.*?)\\<\\/a\\b[^\\>]*\\>@',
'\\1',
$anchor
);
echo $anchor;
}
mysql_close($db);
?>
但这段代码有效,我只更改了一个字符串:
<?php
header('Content-Type: text/html; charset=utf-8');
$db = mysql_connect('localhost', 'db_name', 'db_pass');
mysql_select_db('db_name');
mysql_set_charset('utf8');
$res = mysql_query("SELECT * FROM product_description");
while($row = mysql_fetch_array($res)){
$anchor = 'Lorem ipsum <a href="http://www.google.es">Google</a> Lorem ipsum <a href="http://www.bing.com">Bing</a>'; //Only this string changed!
$anchor = preg_replace(
'@\\<a\\b[^\\>]*\\>(.*?)\\<\\/a\\b[^\\>]*\\>@',
'\\1',
$anchor
);
echo $anchor;
}
mysql_close($db);
?>
1条答案
按热度按时间qc6wkl3g1#
所以。。我解决了我的问题。只要替换一下
.