Domain Manage

page content query

Discussion in 'Website Design' started by SecNam, Oct 27, 2009.

Thread Status:
Not open for further replies.
  1. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,127
    Likes Received:
    37
    im not sure if this is possible but....

    is it possible to a certain keyword on a .php page that when is displayed pulls text from a file and inserts in onthe page.

    also come to think of it, is this possible with an image also
    hope that makes sence lol
     
    Last edited: Oct 27, 2009
  2. Domain Forum

    Acorn Domains Elite Member

    Joined:
    1999
    Messages:
    Many
    Likes Received:
    Lots
     
  3. retired_member13

    retired_member13 Banned

    Joined:
    Jul 2009
    Posts:
    1,317
    Likes Received:
    33
    Do you mean something like this?

    <html><body>This is the text that is in the page but you want a <?php>$insert=file("input_file.txt"); echo $insert; ?> piece of text from the text file in the code to appear before this sentence and on any other pages to put the PHP code in?</body></html>

    The above would pace the output of the file input_file.txt in any page it was used in, and if you change the file the text is changed on all pages that the php code is in. saying that there are lots of ways of doing the same thing.

    Ty

     
  4. retired_member21

    retired_member21 Retired Member

    Joined:
    Apr 2008
    Posts:
    742
    Likes Received:
    13
    not sure - original question is bit vague:-

    Code:
    $original_text = "blah blah keyword1 blah";
    
    $keywords = array('keyword1'=>'filename1.txt','keyword2'=>'filename2.txt');
    foreach($keywords as $kw=>$file)
    {
      $original_text = str_replace($kw,file_get_contents($file),$original_text);
    }
    
     
  5. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,127
    Likes Received:
    37
    yes and no ty

    as im more thinking about it i think it would be better if i can get it so it looks at the url then displays the text or .html/.php

    so for example i have cars.co.uk (i wish) when someone visits that url the index page looks at url in question then as said above brings on the file associated with that url.
     
  6. retired_member13

    retired_member13 Banned

    Joined:
    Jul 2009
    Posts:
    1,317
    Likes Received:
    33
    This is one way of doing it.

    Code:
    code snippet removed
    but you could make the site names into an array and then call the text up by doing a lookup, rather than writing out every site. That's the basics though. Obviously the part that looks up the domain could also be separated out to tidy up the code. I use a lot of this sort of stuff on my sites to allow single template use across multiple sites.
     
    Last edited: Oct 28, 2009
  7. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,127
    Likes Received:
    37
    couldnt get the above to work ty getting header already sent error at top of the page.
     
  8. accelerator United Kingdom

    accelerator Well-Known Member

    Joined:
    Apr 2005
    Posts:
    7,398
    Likes Received:
    109
    I am going to answer your general question in general terms, and that is, php is good for using keywords to retrieve data or files.

    Rgds
     
  9. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,127
    Likes Received:
    37
    that helped me :) (not)
     
  10. accelerator United Kingdom

    accelerator Well-Known Member

    Joined:
    Apr 2005
    Posts:
    7,398
    Likes Received:
    109
  11. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,127
    Likes Received:
    37
  12. Skinner

    Skinner Well-Known Member

    Joined:
    Jul 2008
    Posts:
    4,325
    Likes Received:
    81
    Yeah its possible. I do this using SQL for a quick and nasty way, so I slam page into SQL then use an index page that simply pulls the page out of no where.

    I also do this with includes using a switch statement.

    So you'd have

    index.php
    -cars.inc.php
    -house.inc.php
    -etc

    Then use a switch based on the URL to include the right include :)
     
  13. Skinner

    Skinner Well-Known Member

    Joined:
    Jul 2008
    Posts:
    4,325
    Likes Received:
    81
    I scribbled this into notepad earlier, I'm pretty sure the syntax is right. This isn't the best way to do it, but its the easiest without a templating engine and stacks of SQL :)

    PHP:
    switch($dom $ext) {
        case 
    'cars.co.uk':
            include(
    './cars.inc.php')
        break;

        case 
    'bikes.co.uk':
            include(
    './bikes.inc.php')
        break;
        
        default:
            include(
    './basic.inc.php')
        break;
    }
     
  14. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,127
    Likes Received:
    37
    cheers guys, im working on it a few ways so will reply if i suss what i want it to do
     
  15. Skinner

    Skinner Well-Known Member

    Joined:
    Jul 2008
    Posts:
    4,325
    Likes Received:
    81
    I was editing some code like this, and it thought maybe worth posting as it allows you some basic SEO all in one file.

    PHP:
    <?php 
    switch($dom $ext) {
        case 
    'cars.co.uk':
            
    $header "";
            
    $title "Cars.co.uk - Number 1 Source of Car Information";
            
    $keyword "cars, convertibles, saloon, hatchback, hot hatch";
            
    $desc "The premiere UK Source for Car Information Blah";
            
    $footer "Copyright Cars.co.uk";
            
    // you can add any others here
            
    include('./cars.inc.php')        
        break;

        case 
    'bikes.co.uk':
            
    $header "";
            
    $title "Bikes.co.uk - Number 1 Source of Bike Information";
            
    $keyword "bikes, rally, track, dirt, chopper";
            
    $desc "The premiere UK Source for Bike Information Blah";
            
    $footer "Copyright Bike.co.uk";
            include(
    './bikes.inc.php')
        break;
        
        default:
            include(
    './basic.inc.php')
        break;
    }
    ?>
    Then inside the cars.inc I use <?php echo $header; ?> that way I can customise them as I go all in once place, so its a very very messy, nasty and simple template system that does the job :)

    You can use more includes within the includes but to try and keep it tidy name them like cars.filename.inc.php so all the cars are together :)

    Hard to offer any other advice without knowing more about the project :)
     
Thread Status:
Not open for further replies.

Share This Page