Possible Duplicate:
Regular Expression Sanitize (PHP)
I want to make my links SEO. Before I started the links looked like this:
http://www.domain.tld/index.php?page=blog
My goal was to change it to: http://www.domain.tld/blog
. That works now.
I changed the htaccess to this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^\w+$ index.php?page=$0 [L]
RewriteCond %{THE_REQUEST} index\.php
RewriteCond %{QUERY_STRING} ^page=(\w+)$
RewriteRule ^index\.php$ /%1? [R=301,L]
RewriteRule ^blog/(\d+)-([\w-]+)$ index.php?page=single_news&id=$1&headline=$2
Now I want to change the URIs of the headlines of any blog entry. They looked like this: http://www.domain.tld/index.php?page=single_news&id=2&headline=This%20Is%20A%20Headline
I want to make them looking like this: http://www.domain.tld/blog/2-this-is-a-headline
I am generating my headline-links in the div-class "news_headline" (see below).
<div id="main">
<?php
$query = "SELECT `id`, `headline`, `writer`, `content`, DATE_FORMAT(date,\"%d. %M %Y\") AS `date` FROM `blog` ORDER BY `id` DESC";
$news_resource = mysql_query($query) or die(mysql_error());
?>
<?php
$all_news = array();
$five_news = array();
for($i = 0; $news = mysql_fetch_object($news_resource); $i++){
if($i < 5){
$five_news[] = $news;
}
$all_news[] = $news;
}
?>
<?php foreach($five_news as $news)
{ ?>
<div class="news_bg">
<div class="news_headline"><a href="blog/<?php echo $news->id; ?>-<?php echo $news->headline; ?>"><?php echo $news->headline; ?></a></div>
<div class="news_infoline_top"><?php echo $news->date; ?> · <?php echo $news->writer; ?></div>
<div class="news_text"><?php echo $news->content; ?></div>
</div>
<?php } ?>
</div>
With my htaccess (see above) the links are like this now:
http://www.domain.tld/blog/2-This Is A Headline
I already had help about this and a good guy gave me this code-snippets to make the links looking like I want, but I don't know how to use them:
$urititle = strtolower(preg_replace('/[^\w-]+/','-', $title));
and
$_GET['headline'] != $urititle
I am lost.