Enjoy an ad free experience by logging in. Not a member yet?
Register .
01-03-2013, 09:05 PM
PM User |
#1
New Coder
Join Date: Feb 2012
Posts: 24
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!
01-03-2013, 10:24 PM
PM User |
#2
Regular Coder
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
Quote:
Originally Posted by
milanello72
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 ..
01-03-2013, 10:47 PM
PM User |
#3
New Coder
Join Date: Feb 2012
Posts: 24
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?
01-04-2013, 12:25 AM
PM User |
#4
Regular Coder
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
Quote:
Originally Posted by
milanello72
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
should be what you're using.. you don't leave it like that. unless you use
somewhere.
See what I mean?
01-04-2013, 12:35 AM
PM User |
#5
Regular Coder
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 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).
01-04-2013, 10:49 AM
PM User |
#6
New Coder
Join Date: Feb 2012
Posts: 24
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 ..
01-04-2013, 02:59 PM
PM User |
#7
New Coder
Join Date: Feb 2012
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
I tried to add "AllowEncodedSlashes On" in the .htaccess but it didn't work. Any idea?
01-04-2013, 03:12 PM
PM User |
#8
Regular Coder
Join Date: Sep 2005
Location: UK
Posts: 921
Thanks: 25
Thanked 79 Times in 79 Posts
return urlencode($string);
01-04-2013, 08:43 PM
PM User |
#9
New Coder
Join Date: Feb 2012
Posts: 24
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!
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 08:14 PM .
Advertisement
Log in to turn off these ads.