Spaces in URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MicroBoy
Forum Contributor
Posts: 112
Joined: Sat Mar 14, 2009 5:16 pm

Spaces in URL

Post by MicroBoy »

[Split from unrelated topic and given new Subject by moderator. microboy, please do not change the subject of a thread.]
Why when a row has spaces it just show the first world of that row, and all rows after that are not in the link. Example if the row Firma has "Gorenje 2 series" than in the link It just shows:

Code: Select all

send.php?kodi=example&emri=example&lloji=example&firma=Gorenje
When every row has no spaces everything it's ok. And when I write the link by my self even it has spaces everything it's ok(when I write into browser)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Spaces in URL

Post by requinix »

Code: Select all

<a href=send.php?kodi=example&emri=example&lloji=example&firma=Gorenje 2 series>
You have to put quotes around the href, otherwise the browser will just cut it off at the first space.

Code: Select all

<a href="send.php?kodi=example&emri=example&lloji=example&firma=Gorenje 2 series">
MicroBoy
Forum Contributor
Posts: 112
Joined: Sat Mar 14, 2009 5:16 pm

Re: Spaces in URL

Post by MicroBoy »

I just wrote an example because my link is like this, I put the " around the href but it doesn't work.

Code: Select all

echo "<td><a href=" . $url . "/pjeset/shisni.php?kodi=" . $row['kodi'] . "&emri=" . $row['emri'] . "&lloji=" . $row['lloji'] . "&firma=" . $row['firma'] . "&paisja=" . $row['paisja'] . "&shisjes=" . $row['shisjes'] . " onClick=\"return confirm('A Jeni i Sigurt Që Doni Ta Shisni Këtë Pjesë?') \">Shisni</a></td>";
MicroBoy
Forum Contributor
Posts: 112
Joined: Sat Mar 14, 2009 5:16 pm

Re: Spaces in URL

Post by MicroBoy »

I'm sorry that I made a double post, but I need help so much?
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Spaces in URL

Post by watson516 »

You need to put quotes around your url as stated above. Your code doesn't have it. When it is echoed, there are no quotes.
MicroBoy
Forum Contributor
Posts: 112
Joined: Sat Mar 14, 2009 5:16 pm

Re: Spaces in URL

Post by MicroBoy »

watson516 wrote:You need to put quotes around your url as stated above. Your code doesn't have it. When it is echoed, there are no quotes.
Do you mean around all URL, or around each part where it's a variable? If you can please put the quotes into my link and post it ok.
ghogilee
Forum Newbie
Posts: 19
Joined: Tue Apr 07, 2009 8:45 am
Location: Novi Sad, Serbia

Re: Spaces in URL

Post by ghogilee »

First of all why are you using spaces in your url's?

it's much simpler like this:

Code: Select all

<?php
$somestring = 'Gorenje 2 series';
$fixedstring = strtolower(str_replace(" ", "-", $somestring)); //replace spaces with -, and change case
//and then just
echo '<a href="domain.com/send.php?kodi=example&emri=example&lloji=example&firma=' . $fixedstring . '">Blah blah</a>';
?>
Or if you (or anybody else) want some usefull function here it is:

Code: Select all

<?php
//make small name and without spaces
function fixstring($string) {
    $string = strtolower(str_replace(" ", "-", $string));
    return $string;
}
//usage
$badstring = 'Gorenje 2 series';
echo fixstring($badstring); //this will output gorenje-2-series
?>
MicroBoy
Forum Contributor
Posts: 112
Joined: Sat Mar 14, 2009 5:16 pm

Re: Spaces in URL

Post by MicroBoy »

Meaby you didn't understand me, "kodi, emri, firma" etc... aren't always the same, they depend in the result of each row. I just said an example with "Gorenje 2 Series", and I can't replace spaces with - because in shisni.php the information have to show as in previous page. Not with -.

Code: Select all

echo "<td><a href=" . $url . "/pjeset/shisni.php?kodi=" . $row['kodi'] . "&emri=" . $row['emri'] . "&lloji=" . $row['lloji'] . "&firma=" . $row['firma'] . "&paisja=" . $row['paisja'] . "&shisjes=" . $row['shisjes'] . " onClick=\"return confirm('A Jeni i Sigurt Që Doni Ta Shisni Këtë Pjesë?') \">Shisni</a></td>";
ghogilee
Forum Newbie
Posts: 19
Joined: Tue Apr 07, 2009 8:45 am
Location: Novi Sad, Serbia

Re: Spaces in URL

Post by ghogilee »

MicroBoy wrote:Meaby you didn't understand me, "kodi, emri, firma" etc... aren't always the same, they depend in the result of each row. I just said an example with "Gorenje 2 Series", and I can't replace spaces with - because in shisni.php the information have to show as in previous page. Not with -.

Code: Select all

echo "<td><a href=" . $url . "/pjeset/shisni.php?kodi=" . $row['kodi'] . "&emri=" . $row['emri'] . "&lloji=" . $row['lloji'] . "&firma=" . $row['firma'] . "&paisja=" . $row['paisja'] . "&shisjes=" . $row['shisjes'] . " onClick=\"return confirm('A Jeni i Sigurt Që Doni Ta Shisni Këtë Pjesë?') \">Shisni</a></td>";

Ok, the use urlencode - http://www.php.net/urlencode, and
urldecode for display back - http://www.php.net/manual/en/function.urldecode.php.
I think that this is what you want
MicroBoy
Forum Contributor
Posts: 112
Joined: Sat Mar 14, 2009 5:16 pm

Re: Spaces in URL

Post by MicroBoy »

ghogilee wrote:Ok, the use urlencode - http://www.php.net/urlencode, and
urldecode for display back - http://www.php.net/manual/en/function.urldecode.php.
I think that this is what you want
Thnx a lot. I'm using urlencode at the send page, at the receive I'm not using urldecode because I saw this:

Code: Select all

The superglobals $_GET and $_REQUEST  are already decoded. Using urldecode() on an element in $_GET or $_REQUEST could have unexpected and dangerous results.
p.s. At the receive page I use &_GET to get informations. everything now it's ok.
Post Reply