Error in PHP code to construct URL
I need to fix this URL redirect in header
$siteurl = http://myfirstsite.com
$siteurl2 = http://mysecondsite.com
<a href="<?php ech开发者_如何学Co if (strstr ($_SERVER["REQUEST_URI"], "hus")) {
echo $siteurl;
} else {
echo $siteurl2;
}."/".ereg_replace(" ", "-", $show_wallpaper["caturl"])."-".$show_wallpaper["categoryid"]."-"."1.php"; ?>">
It throws an error now.
You are concatenating against the braces of an if block {}
. Instead, echo
:
<a href="<?php echo if (strstr ($_SERVER["REQUEST_URI"], "hus")) {
echo $siteurl;
} else {
echo $siteurl2;
}
echo "/".ereg_replace(" ", "-", $show_wallpaper["caturl"])."-".$show_wallpaper["categoryid"]."-"."1.php";
?>">
First off, don't use ereg functions. They're deprecated. Use the preg functions instead.
preg_replace('/ /', '-', ...);
Beyond that, the fix is trivial:
if (...) {
header('Location: ' . $siteurl . preg_replace(...));
} else {
header('Location: ' . $siteurl2 . preg_replace(...));
}
精彩评论