0

在上一篇文章的帮助下,我可以在 url 中添加破折号,但是,一旦完成此任务,我就无法加载正确的页面。

部分php代码:

$query_getDisplay = sprintf("SELECT blog.title, blog.description, blog.keywords,
blog.blog_entry,  DATE_FORMAT(blog.updated, '%%M %%e, %%Y') AS formatted, 
blog.blogphoto FROM blog WHERE blog.category = 'videos'
AND DATE_FORMAT(blog.updated, '%%Y-%%m') = %s
ORDER BY blog.updated DESC", GetSQLValueString($var1_getDisplay2, "text"));

} elseif (isset($_GET['title'])) {
  $var2_getDisplay3 = $_GET['title'];

$query_getDisplay = sprintf("SELECT blog.title,blog.description, blog.keywords,
blog.blog_entry,  DATE_FORMAT(blog.updated, '%%M %%e, %%Y') AS formatted,
blog.blogphoto FROM blog WHERE blog.title = %s",
GetSQLValueString($var2_getDisplay3, "text"));

} else {

$query_getDisplay = "SELECT blog.title, blog.blog_entry, blog.description,
blog.keywords,  DATE_FORMAT(blog.updated, '%M %e, %Y') AS formatted,
blog.blogphoto FROM blog WHERE blog.category = 'videos' ORDER BY blog.updated DESC
LIMIT 2";

}

$getDisplay = mysql_query($query_getDisplay, $check_mag) or die(mysql_error());
$row_getDisplay = mysql_fetch_assoc($getDisplay);
$totalRows_getDisplay = mysql_num_rows($getDisplay);
?>

URL 正常工作的代码如下所示

    <div id="recent">
      <h3>Recent Post</h3>
<ul>
        <?php do { ?>
          <li><a href="videos.php?title=<?php echo str_replace(' ',
             '-',$row_getRecent['title']); ?>"
             ><?php echo $row_getRecent['title']; ?></a></li>
          <?php } while ($row_getRecent = mysql_fetch_assoc($getRecent)); ?>
<li> <a></a></li>
      </ul>
    </div>
4

1 回答 1

1

我不确定你为什么要运行str_replaceURL但我想你想要正确的 Url 编码.. 你应该尝试urlencode http://php.net/manual/en/function.urlencode.php

urlencode($row_getRecent['title']); 
于 2012-05-03T04:21:05.553 回答