1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Tag Cloud url

Discussion in 'PHP' started by SharingEngines, Nov 15, 2010.

  1. #1
    Hi,

    I have this code and I like to transform the final url.
    The url result of this code for now is:
    http://www.xxxx.com/index.php?q=west coast customs
    Code (markup):
    And I like to transform in
    http://www.xxxx.com/file_west+coast+customs.html
    Code (markup):

    Is this posssible?

    Thank you for you attention.

    <?php
    
    #DATABASE TAGS
    
    $db_host = ".....";
    $db_user = ".....";
    $db_pass = "....";
    $db_name = "......";
    
    mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
    mysql_select_db($db_name);
    
    function tag_info() { 
    $result = mysql_query("SELECT * FROM Web GROUP BY tags ORDER BY Rand() DESC"); 
    while($row = mysql_fetch_array($result)) { 
    $arr[$row['tags']] = $row['count'];
      } 
    //ksort($arr); 
    return $arr; 
    }
    
    function tag_cloud() {
    
    $min_size = 11;
    $max_size = 25;
    
    # GET THE SMALLEST AND LARGET COUNT NUMBERS
    $sql = mysql_query("SELECT MIN(count),MAX(count) FROM Web");
    list($minimum_count,$maximum_count) = mysql_fetch_row($sql); 
    $spread = $maximum_count - $minimum_count;
    
    if($spread == 0) {
    $spread = 1;
    }
    
    $cloud_html = '';
    $cloud_tags = array();
    
    $step = ($max_size - $min_size)/($spread);
    
    # GRAB THE DATA FROM MySQL
    $sql = mysql_query("SELECT tags,count,Url FROM Web GROUP BY tags ORDER BY Rand() DESC LIMIT 55");
    # USING mysql_fetch_row SO WE CAN USE list()
    while(list($tag,$count,$url) = mysql_fetch_row($sql)) {
    $size = $min_size + ($count - $minimum_count) 
    * $step;
    
    //  $size = ($max_size + $min_size)/$spread;
    $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
    . '" class="tag_cloud" href="index.php?q=' . $url
    . '" class="tag_cloud" href="' . $url
    . '" title="\'' . $tag  . '\' returned a count of ' . $count . '">' 
    . html_entity_decode(stripslashes($tag)) . '</a>';
    }
    $cloud_html = join("|", $cloud_tags) . "";
    return $cloud_html;
    } 
    
    ?>
    
    <?php print tag_cloud(); ?>
    
    Code (markup):

     
    SharingEngines, Nov 15, 2010 IP
  2. freshdevelopment

    freshdevelopment Notable Member

    Messages:
    1,303
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    240
    #2
    This would be solved in .htaccess and not PHP
     
    freshdevelopment, Nov 15, 2010 IP
  3. SharingEngines

    SharingEngines Member

    Messages:
    83
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Can you give me some tips?
    I'm newbee.

    Sorry my english
     
    SharingEngines, Nov 15, 2010 IP
  4. xpertdev

    xpertdev Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Here are the .htaccess code for your problem:

    ReweiteRule ^file_([a-zA-Z0-9_-]).html$ index.php?q=$1 [NC,L]

    You will get query string on get variable by accessing the URL.

    Hope this helps
    Avinash - Xpertdev
     
    xpertdev, Nov 15, 2010 IP
  5. Ankurkr

    Ankurkr Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    this problem can be solved by use of java script.
     
    Ankurkr, Nov 15, 2010 IP
  6. SharingEngines

    SharingEngines Member

    Messages:
    83
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #6
    Thank you, but it gives me a 500 Internal Server Error error
     
    SharingEngines, Nov 16, 2010 IP
  7. xpertdev

    xpertdev Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Sorry typo mistake, replace with this:

    RewriteRule ^file_([a-zA-Z0-9_-]).html$ index.php?q=$1 [NC,L]

    Hope this helps... :)
     
    Last edited: Nov 16, 2010
    xpertdev, Nov 16, 2010 IP
  8. imocoder

    imocoder Member

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #8
    Aren't you looking for this?
    
    $url = 'http://www.xxxx.com/index.php?q=west coast customs';
    echo urlencode($url); 
    //result: http%3A%2F%2Fwww.xxxx.com%2Findex.php%3Fq%3Dwest+coast+customs
    
    Code (markup):
     
    imocoder, Nov 16, 2010 IP
  9. SharingEngines

    SharingEngines Member

    Messages:
    83
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #9
    RewriteRule ^file_([a-zA-Z0-9_-]).html$ index.php?q=$1 [NC,L]
    Code (markup):
    Already try but disen't work

    Already find on net some htaccess files and dosen't work.

    I thik the problem is the php.
    My test site is under http://www.futpt.com
     
    SharingEngines, Nov 16, 2010 IP
  10. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #10
    You need to tidy up the spaces

    replace with this code
    while(list($tag,$count,str_replace(" ",'+',$url)) = mysql_fetch_row($sql)) {
    PHP:
    Then you can run a simple .htacces code
    
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (.[^/]*) /index.php?q=$1 [NC,L]
    
    Code (markup):
    so this '/west+coast+customs' is the same as this '/index.php?q=west+coast+customs' you can add .html if you wish

    Also I'm not sure why you have this line:
    . '" class="tag_cloud" href="index.php?q=' . $url
    
    PHP:
    I dont think you need that.
     
    Last edited: Nov 16, 2010
    MyVodaFone, Nov 16, 2010 IP
  11. SharingEngines

    SharingEngines Member

    Messages:
    83
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #11
    Already replace this line
    while(list($tag,$count,str_replace(" ",'+',$url)) = mysql_fetch_row($sql)) {
    Code (markup):
    But now gives me an error on line 71 (this line) "Fatal error: Can't use function return value in write context in public_html/tags.php on line 71
    while(list($tag,$count,str_replace(" ",'+',$url)) = mysql_fetch_row($sql)) {
    Code (markup):
     
    SharingEngines, Nov 16, 2010 IP
  12. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #12
    Try inserting the str_replace() function here....

    . '" class="tag_cloud" href="' . str_replace(" ",'+',$url)
    PHP:
     
    MyVodaFone, Nov 16, 2010 IP
  13. SharingEngines

    SharingEngines Member

    Messages:
    83
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #13
    You are the best...

    Now I have http://www.xxxxxx.com/west+coast+customs

    If possible I like to have like thishttp://www.xxxxxx.com/west+coast+customs.html

    But when I try to put html like this, gives me a error

    . '" class="tag_cloud" href="' . str_replace(" ",'+',$tag, '.html')
    Code (markup):
     
    SharingEngines, Nov 16, 2010 IP
  14. SharingEngines

    SharingEngines Member

    Messages:
    83
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #14
    Hi,

    I transform the string like this,

    . '" class="tag_cloud" href="' . str_replace(" ",'+',$tag) .'.html'
    Code (markup):
    Now I have west+coast+customs.html in url.

    The only problem is I have "west coast customs.html" in url and search box.

    Any chance to remove this entry "html" of the the search box? maybe in htaccess?

    Thank you for your help
     
    SharingEngines, Nov 17, 2010 IP
  15. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #15
    Try the following, its not tested though, add these two lines to the .htaccess file and remove the .html bit from your line of code above
    
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php?q=([^&]+)\ HTTP/
    
    RewriteRule ^index\.php$ /%1\.html? [R=301,L]
    
    
    
    Code (markup):
     
    MyVodaFone, Nov 17, 2010 IP
  16. SharingEngines

    SharingEngines Member

    Messages:
    83
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #16
    Already tested but it gives me "west+coast+customs"
    the html is missing
     
    SharingEngines, Nov 17, 2010 IP
  17. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #17
    ..and you added the two lines to the htaccess file ?

    
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (.[^/]*) /index.php?q=$1 [NC,L]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php?q=([^&]+)\ HTTP/
    
    RewriteRule ^index\.php$ /%1\.html? [R=301,L]
    
    Code (markup):
     
    MyVodaFone, Nov 17, 2010 IP
  18. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #18
    ..and you added the two lines to the htaccess file ? try this one

    
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (.[^/]*) /index.php?q=$1 [L]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php?q=([^&]+)\ HTTP/
    
    RewriteRule ^index\.php$ /%1\.html? [R=301,L]
    
    Code (markup):
     
    MyVodaFone, Nov 17, 2010 IP
  19. SharingEngines

    SharingEngines Member

    Messages:
    83
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #19
    I have removed in this line the "html"
    . '" class="tag_cloud" href="'. str_replace(" ",'+',$tag)
    Code (markup):
    I have My htaccess like that

    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (.[^/]*) /index.php?q=$1 [L]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php?q=([^&]+)\ HTTP/
    
    RewriteRule ^index\.php$ /%1\.html? [R=301,L]
    
    Code (markup):
    and the result is "west+coast+customs"
     
    SharingEngines, Nov 17, 2010 IP
  20. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #20
    Hmm sorry I'm not that well up on my htaccess... one last try, if this one doesnt work, start a new thread with a regards to the htaccess code.


    The code below should take west+coast+customs" and redirect it to west+coast+customs.html" copy it as one piece, no line breaks

    
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.[^/]*) /index.php?q=$1 [L]
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php?q=(.[^/]*)\ HTTP/
    RewriteRule ^index\.php$ /%1\.html? [R=301,L]
    
    Code (markup):
     
    MyVodaFone, Nov 17, 2010 IP