Page 1 of 1
Spaces in URL
Posted: Sat Mar 28, 2009 3:38 pm
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)
Re: Spaces in URL
Posted: Sat Mar 28, 2009 6:41 pm
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">
Re: Spaces in URL
Posted: Sun Mar 29, 2009 9:37 am
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>";
Re: Spaces in URL
Posted: Tue Apr 07, 2009 2:26 pm
by MicroBoy
I'm sorry that I made a double post, but I need help so much?
Re: Spaces in URL
Posted: Tue Apr 07, 2009 3:17 pm
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.
Re: Spaces in URL
Posted: Tue Apr 07, 2009 4:01 pm
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.
Re: Spaces in URL
Posted: Tue Apr 07, 2009 5:50 pm
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
?>
Re: Spaces in URL
Posted: Wed Apr 08, 2009 11:53 am
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>";
Re: Spaces in URL
Posted: Wed Apr 08, 2009 12:05 pm
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
Re: Spaces in URL
Posted: Wed Apr 08, 2009 3:29 pm
by MicroBoy
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.