How to create titles from page name ?

Discussion in 'PHP' started by poseidon, Sep 20, 2006.

  1. #1
    well I am generating pages from database and I want to keey SEO friendly titles for every page. The pages are like dealers-of-variable.php so I want the page title to be <title>Delaers of Variable</title> :) How can I do this ? mind you,first I have to know the name of the page using php code and than have to modify it to create title. I think the code will be something like this.

    <?php
    $page_name //we have to find this..but how ???

    $title=[using regexp make page name into proper titles]
    ?>

    <title><echo $title></title>

    Thanks
     
    poseidon, Sep 20, 2006 IP
  2. Galaxyrover

    Galaxyrover Well-Known Member

    Messages:
    179
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #2
    Take page name from $_SERVER["REQUEST_URI"].
     
    Galaxyrover, Sep 20, 2006 IP
  3. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #3
    wmtips, Sep 20, 2006 IP
  4. KC TAN

    KC TAN Well-Known Member

    Messages:
    4,792
    Likes Received:
    353
    Best Answers:
    0
    Trophy Points:
    155
    #4
    Hi poseidon,

    You can pull out the filename without the extension by using:
    
    $file = basename($path, ".php"); // $file is set to actual name without the extension
    
    //OR you can use pathinfo() if many types of files are used besides php
    
    PHP:
    To get rid of the dashes,
    
    $title=str_replace("-", " ", $file);
    
    PHP:
     
    KC TAN, Sep 20, 2006 IP
  5. wormser

    wormser Well-Known Member

    Messages:
    112
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    138
    #5
    Also
    $newtitle = ucwords($title)
     
    wormser, Sep 20, 2006 IP
  6. poseidon

    poseidon Banned

    Messages:
    4,356
    Likes Received:
    246
    Best Answers:
    0
    Trophy Points:
    0
    #6
    And what exactly this will do ?
     
    poseidon, Sep 20, 2006 IP
  7. wormser

    wormser Well-Known Member

    Messages:
    112
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    138
    #7
    That will Capitalize the first letter of each word.
     
    wormser, Sep 20, 2006 IP