Htaccess - Rewrite spaces with Replace function

Discussion in 'PHP' started by zaay, Aug 7, 2009.

  1. #1
    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 !
     
    zaay, Aug 7, 2009 IP
  2. oop

    oop Peon

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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:
     
    oop, Aug 7, 2009 IP
  3. zaay

    zaay Member

    Messages:
    269
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #3
    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'], '&lt;a&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;'));
            $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:
     
    zaay, Aug 7, 2009 IP
  4. oop

    oop Peon

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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
     
    oop, Aug 7, 2009 IP
  5. zaay

    zaay Member

    Messages:
    269
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #5
    No, i am sorry. But still the same :(

    Thanx for all the help !
     
    zaay, Aug 7, 2009 IP
  6. oop

    oop Peon

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    $seotitle = preg_replace('/[^a-zA-Z0-9_]+/','_',$row['title']); //removes everything that is not with a-z or A-Z or 0-9
     
    oop, Aug 7, 2009 IP
  7. zaay

    zaay Member

    Messages:
    269
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #7
    Yuuupiiii ... That's working oop ! Thank you very very much ! ;)
     
    zaay, Aug 7, 2009 IP