Hello Everyone ! Here is my code: $date = $row['date']; $tags= $row['tags']; $title = htmlspecialchars ($row['title']); $news = nl2br (strip_tags ($row['newstext'], '<a><b><i><u>')); $seotitle = preg_replace("/([\W]+)/", "-", strtolower($title)); /* display the data */ echo "<h1><a href='http://mysite.php/all-news-".$row['id']."-".$row['title']."'>$title</a></h1>"; echo "<h2>".$tags.",</h2>"; PHP: So i want to replace all spaces and everything in title with "-" , but i have problems with it .. My function seotitle is not working .. Please help me !
use preg_replace('/^[a-zA-Z0-9]+/','_',$title); //removes everything that is not withi a-z or A-Z or 0-9 PHP: AND YOU NEED TO CHANGE THIS echo "<h1><a href='http://mysite.php/all-news-".$row['id']."-".$row['title']."'>$title</a></h1>"; PHP: TO echo "<h1><a href='http://mysite.php/all-news-".$row['id']."-".$seotitle."'>".$title."</a></h1>"; PHP:
Hello ! Everything i got is only that url: http://mysite.com/all-news-2-_another News For Tags And Long Very Long It add only that _ before title $date = $row['date']; $tags= $row['tags']; $title = htmlspecialchars ($row['title']); $news = nl2br (strip_tags ($row['newstext'], '<a><b><i><u>')); $seotitle = preg_replace('/^[a-zA-Z0-9]+/','_',$title); //removes everything that is not withi a-z or A-Z or 0-9 /* display the data */ echo "<h1><a href='http://mysite.com/all-news-".$row['id']."-".$seotitle."'>".$title."</a></h1>"; PHP:
try changing it to $seotitle = preg_replace('/^[a-zA-Z0-9]+/','_',$row['title']); //removes everything that is not with a-z or A-Z or 0-9
$seotitle = preg_replace('/[^a-zA-Z0-9_]+/','_',$row['title']); //removes everything that is not with a-z or A-Z or 0-9