Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem in displaying a URL with dash

    How could I display a URL with dash?
    I have
    Code:
    href="/calcioitalia/'.$page.'/'.$id_team.'/'.$name.'.html"
    I want to transform calcioitalia/teams/1/Juventus F.C. Torino.html in
    calcioitalia/teams/1/Juventus-F.C.-Torino.html

    thank you!

  • #2
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    Quote Originally Posted by milanello72 View Post
    How could I display a URL with dash?
    I have
    Code:
    href="/calcioitalia/'.$page.'/'.$id_team.'/'.$name.'.html"
    I want to transform calcioitalia/teams/1/Juventus F.C. Torino.html in
    calcioitalia/teams/1/Juventus-F.C.-Torino.html

    thank you!
    PHP Code:
    $team str_replace("%20""-"$id_team); 
    PHP Code:
    href="/calcioitalia/'.$page.'/'.$team.'/'.$name.'.html" 
    But, if you want a bit more than that, and you probably do, if you are working with URLs, you should take a look at the urlencode() function.

    PHP Code:
    $team urlencode($id_team
    Last edited by tempz; 01-03-2013 at 10:31 PM.

  • #3
    New Coder
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you for your message!
    I foun this function:
    Code:
    function seoUrl($string) {      
             //Strip any unwanted characters
             $string = preg_replace("/[^A-Za-z0-9_\s-]/", "", $string);
             //Clean multiple dashes or whitespaces
             $string = preg_replace("/[\s-]+/", " ", $string);
             //Convert whitespaces and underscore to dash
             $string = preg_replace("/[\s_]/", "-", $string);
             return $string;
    }
    I have another problem!
    In horizontalmenu.php I will have:
    Code:
    href="/calcioitalia/'.$page.'/'.$id_team.'/'.$name.'.html"
    where $name=seoUrl($name);
    *********************************
    But how will display teams.php in index.php?? I use
    Code:
    if (isset($_GET['pagina']) and $_GET['pagina'] == 'teams' and isset($_GET['id_team']) and isset($_GET['name']))
    {
             include('./includes/teams.php');
    }
    but doesn't work because in menuhorizontal i used seoUrl.
    I have this message: The requested URL /calcioitalia/teams/2/AC-Milan.php was not found on this server.
    How could I solve this problem?

  • #4
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    Quote Originally Posted by milanello72 View Post
    thank you for your message!
    I foun this function:
    Code:
    function seoUrl($string) {      
             //Strip any unwanted characters
             $string = preg_replace("/[^A-Za-z0-9_\s-]/", "", $string);
             //Clean multiple dashes or whitespaces
             $string = preg_replace("/[\s-]+/", " ", $string);
             //Convert whitespaces and underscore to dash
             $string = preg_replace("/[\s_]/", "-", $string);
             return $string;
    }
    I have another problem!
    In horizontalmenu.php I will have:
    Code:
    href="/calcioitalia/'.$page.'/'.$id_team.'/'.$name.'.html"
    where $name=seoUrl($name);
    *********************************
    But how will display teams.php in index.php?? I use
    Code:
    if (isset($_GET['pagina']) and $_GET['pagina'] == 'teams' and isset($_GET['id_team']) and isset($_GET['name']))
    {
             include('./includes/teams.php');
    }
    but doesn't work because in menuhorizontal i used seoUrl.
    I have this message: The requested URL /calcioitalia/teams/2/AC-Milan.php was not found on this server.
    How could I solve this problem?
    The
    PHP Code:
    $string 
    should be what you're using.. you don't leave it like that. unless you use
    PHP Code:
    $string 
    somewhere.

    See what I mean?

  • #5
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    PHP Code:
     
    preg_replace
    (' ''-'$id_team//whitespaces
    preg_replace('%20 ''-'$id_team//%20
    preg_replace('#\W+#''-'$id_team//description below. 
    \W is any non-word character, e.g not A-Z, a-z, 0-9, or underscore (lower case \w is the inverse, so watch your typing).

  • #6
    New Coder
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I used
    Code:
    preg_replace(' ', '-', $name); //whitespaces
    preg_replace('%20 ', '-', $name); //%20
    preg_replace('#\W+#', '-', $name); //description below. 
           href="/calcioitalia/'.$page.'/'.$id_team.'/'.$name.'.html"
    but my url is calcioitalia/teams/1/Juventus F.C. Torino.html
    so without '-'

    If I use
    Code:
    href="/calcioitalia/'.$page.'/'.$id_team.'/'.seoUrl($name).'.html"
    where
    Code:
    function seoUrl($string) {
            //Unwanted:  {UPPERCASE} ; / ? : @ & = + $ , . ! ~ * ' ( )
          //  $string = strtolower($string);
            //Strip any unwanted characters
            $string = preg_replace("/[^A-Za-z0-9_\s-]/", "", $string);
            //Clean multiple dashes or whitespaces
            $string = preg_replace("/[\s-]+/", " ", $string);
            //Convert whitespaces and underscore to dash
            $string = preg_replace("/[\s_]/", "-", $string);
            return $string;
    }
    then I will obtain the link with '-'
    calcioitalia/teams/1/Juventus-F.C.-Torino.html
    but I have the message
    "The requested URL /calcioitalia/teams/1/Juventus-FC-Torino.php was not found on this server."

    so the problem is that I must to decode $name in index.php.
    Last edited by milanello72; 01-04-2013 at 11:02 AM.

  • #7
    New Coder
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried to add "AllowEncodedSlashes On" in the .htaccess but it didn't work. Any idea?

  • #8
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    return urlencode($string);
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #9
    New Coder
    Join Date
    Feb 2012
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I found at it works!
    Code:
    RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/([a-zA-Z0-9-.\s]+)/?.html$ index.php?page=
    $1&id_team=$2&name=$3 [L,QSA]
    I put - in ([a-zA-Z0-9-.\s]+)
    Thank u for your messages!


  •  

    Posting Permissions

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