#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    87
    Rep Power
    5

    Creating urls from an array


    Hi there,

    I am trying to output a list of urls from a list of keywords in a text file. So for example my text file has 100 keywords, one per line, and I want each keyword to be the term="$keyword" in the url.

    I have successfully created the array from the text file using the following:

    PHP Code:
    <?php
    $file 
    fopen("keywords.txt""r");
    $keywords = array();

    while (!
    feof($file)) {
       
    $keyworlds[] = fgets($file);
    }

    fclose($file);

    ?>
    Here is the URL that I want the keyword to appear in:

    http://www.myurl.com/?utm_source=google&utm_medium=cpc&utm_term=$keywords&utm_campaign=my+link+test";

    Any help much appreciated.

    Cheers
    Volterony
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    your code says both $keywords and $keyworlds, you're probably getting an error.

    Also, just do this inside your WHILE:
    PHP Code:
       $keywords[] = 'http://www.myurl.com/?utm_source=google&utm_medium=cpc&utm_term=' urlencode(trim(fgets($file))) . '&utm_campaign=my+link+test'
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    87
    Rep Power
    5
    Originally Posted by ManiacDan
    your code says both $keywords and $keyworlds, you're probably getting an error.

    Also, just do this inside your WHILE:
    PHP Code:
       $keywords[] = 'http://www.myurl.com/?utm_source=google&utm_medium=cpc&utm_term=' urlencode(trim(fgets($file))) . '&utm_campaign=my+link+test'
    Awesome!! Works fine.

    I've done print_r($keywords); just above the fclose($file); and its dumped all the urls correctly to the screen. However is there a way of displaying the urls without all the array gubbings so that its just the urls and nothing else.

    Cheers
    Volterony
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    PHP Code:
      echo 'http://www.myurl.com/?utm_source=google&utm_medium=cpc&utm_term=' urlencode(trim(fgets($file))) . '&utm_campaign=my+link+test' "\n<br />\n"
    And no, I will not help you make them clickable. That exercise is left up to you.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    87
    Rep Power
    5
    Originally Posted by ManiacDan
    PHP Code:
      echo 'http://www.myurl.com/?utm_source=google&utm_medium=cpc&utm_term=' urlencode(trim(fgets($file))) . '&utm_campaign=my+link+test' "\n<br />\n"
    And no, I will not help you make them clickable. That exercise is left up to you.
    Thanks very much for your help.

    Regards
    Volterony.

IMN logo majestic logo threadwatch logo seochat tools logo