$ _GET preg_replace无法正常工作

时间:2016-07-08 20:43:59

标签: php get preg-replace

这是什么不能一次又一次地这样做.. lol

if (!isset($_GET['hash'])) {
  //we give the value of the starting row to 0 because nothing was found in URL
  $hash = 'Teen' . ' ' . chr(38) . ' ' .  'Young Adult';
//otherwise we take the value from the URL
} else {
 //if (strpos($_GET['hash'], '&') !== false) {
$regex = "~[ ]\K&~";
$hash = preg_replace($regex, chr(38), $_GET['hash']);
//$hash = preg_replace('/&/', chr(38) ,$_GET['hash']);
//$hash  = str_replace("&", chr(38), $_GET['hash']);
echo $hash;
//$hash =
//}
}

//// --- etc etc

$DBH = new PDO($hostDb, $user, $password);

$WTH = $DBH -> prepare( "SELECT asin FROM asin WHERE active=1 AND node = :hash LIMIT $startrow, 10" );
$WTH->bindParam(':hash', $hash, PDO::PARAM_STR);
$WTH->setFetchMode(PDO::FETCH_ASSOC);
$WTH -> execute();

foreach($wea as $item)
{
echo '<td>';
echo '<a href="'.$_SERVER['PHP_SELF'].'?hash='.$item["node"].'">' . $item["node"] . '</a>';
echo '</td>';
echo '<td>';
echo $item["c"];
echo '</td>';
echo '</tr>';
}
echo '</td></tr></table>';
echo '</td></tr></table>';

如果这样运行,回声只显示Teen ???而不是Teen & Young Adult?救命?显然mysql不会采取&amp ;.任何解决方案?

0 个答案:

没有答案