SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help me with passing clean URL with special characters

    I'm having issues cleaning out special characters from my script
    currently I'm using the toAscii function(below) and it is removing all special characters such as %,$,# and so on, and it does work

    this is how a cleaned URL looks like

    http://www.site.cxx/latest/this-is-test.html


    but when I click on the actual link it doesn't work just sends me back to the home page. Any ideas

    thanks



    here is the code that retrieves from DB

    PHP Code:
    <?php    while($row=mysql_fetch_assoc($getAll)){    ?> 
        
      <div class="news">
        <span class="antetitulo">text"</span>
        <br />
        <h2 class="title h2">
          <a href="http://www.site.cxx/<?=str_ireplace(" ","-",html_entity_decode($row['genre']));?>/<?php echo toAscii($row['name']); ?>.html"><?=html_entity_decode($row['name']);?></a> 
        </h2>
         <img src="http://www.site.cxx/images/<?=$row['image'];?>" width="350"   height="103" />

        <div class="text">

       <?php echo substr(strip_tags($row['description']),0,130)  ?>.</span></div>
        <br class="c" />
      </div>

      <?php    $i++;    }?>

    I'm also trying to "clean" characters using this function

    PHP Code:
    <?php
    setlocale
    (LC_ALL'en_US.UTF8');
    function 
    toAscii($str$replace=array(), $delimiter='-') {
        if( !empty(
    $replace) ) {
            
    $str str_replace((array)$replace' '$str);
        }

        
    $clean iconv('UTF-8''ASCII//TRANSLIT'$str);
        
    $clean preg_replace("/[^a-zA-Z0-9\/_|+ -]/"''$clean);
        
    $clean strtolower(trim($clean'-'));
        
    $clean preg_replace("/[\/_|+ -]+/"$delimiter$clean);

        return 
    $clean;
    }
    ?>
    this is my .htaccess

    PHP Code:
    RewriteRule ^([^/]*)/([^/]*)\.html$ /news.php?cat=$1&news=$[L

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Sinz,

    It's too late this evening to answer this so please refer to the tutorial linked in my signature as it will lead you through the development of the solution.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •