How can I set up local page generation like this in PHP

Discussion in 'PHP' started by amanamission, Sep 13, 2007.

  1. #1
    This site is using some script to replace local terms every time they occur in title, url, and text.

    www.dsl-internet-dsl-service.com/ca/willits.html
    www.dsl-internet-dsl-service.com/il/chicago.html
    www.dsl-internet-dsl-service.com/ny/buffalo.html
    www.dsl-internet-dsl-service.com/va/alexandria.html

    Notice that every page is the same, except for the state/city name is substituted. It looks like a PHP call function drawing on a MYSQL database, but I really don't know how to set this up.
    What is this easiest way to apply this principle to a real estate site?
     
    amanamission, Sep 13, 2007 IP
  2. killerj

    killerj Active Member

    Messages:
    765
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    95
    #2
    I assume they have assigned a php variable(fetched through Mysql) for the city/states and have used mod rewrite to change the extension from php to html .
     
    killerj, Sep 13, 2007 IP
  3. amanamission

    amanamission Notable Member

    Messages:
    1,936
    Likes Received:
    138
    Best Answers:
    0
    Trophy Points:
    210
    #3
    That's what I think, too. Anyone care to come up with the code for this? I really don't know enough to write it from scratch.
     
    amanamission, Sep 13, 2007 IP
  4. xemiterx

    xemiterx Peon

    Messages:
    62
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It's probably using this common htaccss method:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    HTML:
    Any request that is not a valid file or directory (basically a 404) will run the index.php file on the server root, without changing the address in the users address bar.

    You then use your index.php to parse the requested url:

    $request_parts = split('/', $_SERVER['REQUEST_URI']);
    PHP:
    and query your db and display content accordingly.
     
    xemiterx, Sep 13, 2007 IP
  5. tamen

    tamen Peon

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I run a similar site where the parts changed are city and state. The url part can be done a above.

    In the index.php I just get the content-template from the database. Eample: Hi from %city%, %sate%!

    And do:
    $text = str_replace('%city%', $city, $text);
    $text = str_replace('%state%', $state, $text);

    end then echo $text where needed.
    $city and $state of course holds the city-/state-name called.
     
    tamen, Sep 14, 2007 IP
    amanamission likes this.