SitePoint Sponsor

User Tag List

Results 1 to 24 of 24
  1. #1
    Non-Member
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Generating content from a form

    ok here is what I have:

    Code:
    <html>
    <body><form action="create.php" method="GET">
    Please enter Search Term: <input type="text" name="id" value="">
    <input type="submit" />
    </form></body>
    </html>
    Code:
    <?php 
     
    // generate.php - creates the page identified in 'id' and creates a page out of it 
     
    if (isset($_GET['id']) && !empty($_GET['id'])) { 
     
    $pagetemplate = '
    <?php $file = "http://news.search.yahoo.com/news/rss?p='.$_GET['id'].'+&mp;ei=UTF-8&mp;fl=0&mp;x=wrt"; ?>
    				 <html> 
    				 <head> 
    					 <title>'.$_GET['id'].'</title> 
    				 </head> 
     
    				 <body> 
    					 <h1>'.$_GET['id'].'</h1> 
    	 <? include("parser.php"); ?>
    				 </body> 
    				 </html>'; 
     
    $file = "html/".$_GET['id'].".php"; 
     
    if (!$handle = fopen($file, "a")) { 
    	die("Cannot Open File"); 
    } 
     
    if (!fwrite($handle, $pagetemplate)) { 
    	 die("Cannot Write to File"); 
    } 
     
    echo "Your resluts have been generated. Please click <a href='".$file."'>here</a> to see them."; 
     
    fclose($handle); 
    } 
     
    ?>
    and here is what it does:

    http://www.mrlen.com/submit.php

    Now, I have a new problem. The Yahoo! RSS URL requires that each search term has a + separating the search terms. So far I can't add more than a singlar search term.

    ie:

    Hurricane will work
    Hurricane Katrina will not work

    Can someone help me with this problem?

    Also, how can I change it so that after submitting it goes straight to the generated page? I don't want to click to see results.

    Also, if I enter the same search term twice, it will add it to the same page twice. How can I fix that?

    MrLeN

  2. #2
    SitePoint Addict ruchit's Avatar
    Join Date
    Sep 2005
    Location
    miDDle oF NoWHere
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use urlencode('string') ... before passing the string to Yahoo!
    work together - make world a better place
    Outsource to India
    Web Design India
    Affordable Webhosting

  3. #3
    Non-Member
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am sorry, but I don't understand.

    Could you please explain a little more what I need to do?

    MrLeN

  4. #4
    *munch munch* killerkooki's Avatar
    Join Date
    Sep 2004
    Location
    Singapore
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php $file "http://news.search.yahoo.com/news/rss?p=" urlencode($_GET['id']) . "+&mp;ei=UTF-8&mp;fl=0&mp;x=wrt"?>
    Does that do the trick?

  5. #5
    Non-Member
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Parse error: parse error, unexpected T_STRING in /home/mrlen/public_html/create.php on line 8

  6. #6
    SitePoint Addict ruchit's Avatar
    Join Date
    Sep 2005
    Location
    miDDle oF NoWHere
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $file "http://news.search.yahoo.com/news/rss?p='.urlencode($_GET['id']).'&ei=UTF-8&fl=0&x=wrt"
    work together - make world a better place
    Outsource to India
    Web Design India
    Affordable Webhosting

  7. #7
    Non-Member
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I changed it to:

    <?php $file =
    "http://news.search.yahoo.com/news/rss?p='. urlencode($_GET['id']) .'+&mp;ei=UTF-8&mp;fl=0&mp;x=wrt"; ?>

    and now it works!

    Thank you very much!

    MrLeN

  8. #8
    Non-Member
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh thanks ruchit, we posted at the same time

    Now, the only problem is that Yahoo RSS doesn't work with more than two keywords. It has to be one or two. I think I have to try and limit the search box to two words somehow.

    MrLeN

  9. #9
    SitePoint Addict ruchit's Avatar
    Join Date
    Sep 2005
    Location
    miDDle oF NoWHere
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you should not use '&mp;' instead use '&' only in this case... also '&mp;' is wrong... u have to use '&amp;'.. but that is not required here
    copy&paste the code from my previous post
    work together - make world a better place
    Outsource to India
    Web Design India
    Affordable Webhosting

  10. #10
    Non-Member
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fixed

    Thanks heaps.

    Can anyone help me with my other probs?

    How can I change it so that after submitting it goes straight to the generated page? I don't want to click to see results.

    Also, if I enter the same search term twice, it will add it to the same page twice. How can I fix that?

    MrLeN

  11. #11
    SitePoint Addict ruchit's Avatar
    Join Date
    Sep 2005
    Location
    miDDle oF NoWHere
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad you fixed it.
    Quote Originally Posted by MrLeN
    How can I change it so that after submitting it goes straight to the generated page? I don't want to click to see results.
    Do you mean something like this
    Try my Free Search Engine Rank Tracker
    work together - make world a better place
    Outsource to India
    Web Design India
    Affordable Webhosting

  12. #12
    Non-Member
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, how it just goes straight to the results and doesn't ahve a page in between.

    MrLeN

  13. #13
    Non-Member
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried placing this in the bottom:

    Code:
    <?php
    header("Location: http://www.mrlen.com.com/html/".$_GET['id'].".php"); /* Redirect browser */
    
    /* Make sure that code below does not get executed when we redirect. */
    exit;
    ?>


    but I think it is intefering with the script be fore it executes.

    MrLeN

  14. #14
    SitePoint Addict ruchit's Avatar
    Join Date
    Sep 2005
    Location
    miDDle oF NoWHere
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MrLeN
    Yeah, how it just goes straight to the results and doesn't ahve a page in between.

    MrLeN
    Why do you need a page in-between.. just query Yahoo and output the results.

    In my example.. I am querying 12 different search engines for their first 3 pages.. and I don't have any pages in-between.

    WHy are you creating a file... why don't you just parse & output the results.
    work together - make world a better place
    Outsource to India
    Web Design India
    Affordable Webhosting

  15. #15
    Non-Member
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because the file will be used as web pages, for content. I am just getting the basic structure up now, but soon I will add a template and other information with includes.

    I have it doing exactly what I needed, except I don't want to see that page. I just want it to go straight to the file after it has built it.

    MrLeN

  16. #16
    SitePoint Addict ruchit's Avatar
    Join Date
    Sep 2005
    Location
    miDDle oF NoWHere
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where are you putting this piece
    PHP Code:
    <?php
    header
    ("Location: http://www.mrlen.com.com/html/".$_GET['id'].".php"); /* Redirect browser */

    /* Make sure that code below does not get executed when we redirect. */
    exit;
    ?>
    also, did you try using client-side re-direction?
    work together - make world a better place
    Outsource to India
    Web Design India
    Affordable Webhosting

  17. #17
    Non-Member
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I put it at the very bottom of the create.php code.

    It is hard for me to put redirection in that page, because it's not actually a page as such. It's more of a script.

    People go to submit.php and submit.php sends an action to create.php

    If i put a redirect in create.php it redirects before the page has a chance to execute (well, that's my theory on why it isn't working).

    What I need is some php code that says, ok, the script has been executed now what? Let's redirect to the page we just built.

    ie:

    I need to swap:

    Code:
    echo "Your results have been generated. Please click <ahref='".$file."'>here</a> to see them."; 


    with a redirect of some sort.

    MrLeN

  18. #18
    Non-Member
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I ahve put in a meta redirect for now. I don't like it, but it will do for now.

    Code:
    echo '
    <meta http-equiv="Refresh" content="0;url='.$file.'">
    ';


    MrLeN

  19. #19
    SitePoint Addict ruchit's Avatar
    Join Date
    Sep 2005
    Location
    miDDle oF NoWHere
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can u post code of your page with redirect line in place??
    work together - make world a better place
    Outsource to India
    Web Design India
    Affordable Webhosting

  20. #20
    Non-Member
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <?php 
    
    // generate.php - creates the page identified in 'id' and creates a page out of it 
    
    if (isset($_GET['id']) && !empty($_GET['id'])) { 
    
    $pagetemplate = '
    <?php $file = "http://news.search.yahoo.com/news/rss?p='.urlencode($_GET['id']).'&ei=UTF-8&fl=0&x=wrt"; ?>
    <html> 
    <head> 
    <title>'.$_GET['id'].'</title> 
    </head> 
    
    <body> 
    <h1>'.$_GET['id'].'</h1> 
    <? include("parser.php"); ?>
    </body> 
    </html>'; 
    
    $file = "html/".$_GET['id'].".php"; 
    
    if (!$handle = fopen($file, "a")) { 
    die("Cannot Open File"); 
    } 
    
    if (!fwrite($handle, $pagetemplate)) { 
    die("Cannot Write to File"); 
    } 
    
    //echo "Your results have been generated. Please click <ahref='".$file."'>here</a> to see them."; 
    echo '
    <meta http-equiv="Refresh" content="0;url='.$file.'">
    ';
    
    fclose($handle); 
    } 
    
    ?> 
    <?php 
    //header("Location: http://www.mrlen.com/html/test.php");
    //exit; 
    ?> 


  21. #21
    SitePoint Addict ruchit's Avatar
    Join Date
    Sep 2005
    Location
    miDDle oF NoWHere
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i am wondering.. why you are not getting any errors in this becuase you are still outputting the content then trying to change headers.. hope this helps..
    PHP Code:
    <?php 
    ob_start
    ();
    // generate.php - creates the page identified in 'id' and creates a page out of it 

    if (isset($_GET['id']) && !empty($_GET['id'])) { 

    $pagetemplate '
    <?php $file = "http://news.search.yahoo.com/news/rss?p='
    .urlencode($_GET['id']).'&ei=UTF-8&fl=0&x=wrt"; ?>
    <html> 
    <head> 
    <title>'
    .$_GET['id'].'</title> 
    </head> 

    <body> 
    <h1>'
    .$_GET['id'].'</h1> 
    <? include("parser.php"); ?>
    </body> 
    </html>'


    $file "html/".$_GET['id'].".php"

    if (!
    $handle fopen($file"a")) { 
    die(
    "Cannot Open File"); 


    if (!
    fwrite($handle$pagetemplate)) { 
    die(
    "Cannot Write to File"); 


    fclose($handle); 

    header("Location: http://www.mrlen.com/html/test.php");


    ?>
    work together - make world a better place
    Outsource to India
    Web Design India
    Affordable Webhosting

  22. #22
    Non-Member
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have those parts edited out

    Yes, that worked fine mate!

    Thanks.

    Except I changed it to:

    Code:
    header("Location: /$file");
    


    Now, I am just about finished with all my problems. By the way I have rectified the double writing problem by changing:

    Code:
    if (!$handle = fopen($file, "a")) { 
    

    to
    Code:
    if (!$handle = fopen($file, "w")) { 
    


    MrLeN

    P.S. Now I just have to find out how to prevent people from entering 3 keywords and I am set!

  23. #23
    SitePoint Addict ruchit's Avatar
    Join Date
    Sep 2005
    Location
    miDDle oF NoWHere
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    great.
    for 3 keywords part, try substr_count() in PHP. check the javascript thread for the solution
    work together - make world a better place
    Outsource to India
    Web Design India
    Affordable Webhosting

  24. #24
    Non-Member
    Join Date
    Apr 2001
    Location
    Melbourne, Australia
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I am still trying to figure out how to implement it

    I have a new problem now. The web page file names are being generated with spaces in them. I don't suppose that this would be too much of a concern, but I don't think it's right. Is there a way to get the php to generate a - or a _ for use in the filenames? Like to replace the space with a - or a _?

    So:

    Angeline Jollie.php

    would become:

    Angelina-Jollie.php

    or even

    AngelinaJollie.php

    would do.

    MrLeN


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •