1

The urls are encoded using urlencode().

www.myweb.com/pahe.html?artist=Taylor+Swift

I'm grabbing the string value to be able to pass via jquery's $post() to a php

$.post(my.php', 
     { word:"Taylor Swift" },

How can I pass a string as Taylor Swift instead of Taylor+Swift?

Becky
  • 5,467
  • 9
  • 40
  • 73
  • 6
    Use urldecode() function. – Vlastislav Novák Jun 25 '15 at 12:45
  • `+` is an encoded space in a URL parameter. – Phylogenesis Jun 25 '15 at 12:48
  • @VlastislavNovák thanks. can this be done in my html itself? Could you explain a bit more. :) – Becky Jun 25 '15 at 12:50
  • 1
    @Becky You can send encoded string (Taylor+Swift) with jquery and use urldecode() function in file my.php. – Vlastislav Novák Jun 25 '15 at 12:55
  • @VlastislavNovák that explains it better. SO basically `urldecode()` removes all `+` in php. So I don't have to worry about the sting values in my html. right? – Becky Jun 25 '15 at 12:57
  • @VlastislavNovák is this a better solution? `utf8_decode(urldecode("") );` – Becky Jun 25 '15 at 13:03
  • @Bekky There's no need to use utf8_decode. You don't have to worry about it, if urldecode() function is used in PHP script. – Vlastislav Novák Jun 25 '15 at 13:07
  • @VlastislavNovák There seems to be a huge difference in the output between `urldecode("Ant%C3%B4nio+Carlos+Jobim");` and `utf8_decode(urldecode("Ant%C3%B4nio+Carlos+Jobim"))` according to [this post](http://stackoverflow.com/questions/1756862/url-decoding-in-php) – Becky Jun 25 '15 at 13:13

2 Answers2

1

You can use str_replace to replace all + with spaces:

$artist = "Taylor+Swift";
echo urldecode($artist); // Taylor Swift

JavaScript / HTML

If you don't have access to the server-side. You can do:

{ word: "Taylor+Swift".replace(/+/g, ' ') }
Downgoat
  • 13,771
  • 5
  • 46
  • 69
0

You can try this:

urldecode($url);
LugiHaue
  • 2,702
  • 1
  • 15
  • 13
  • thanks. where could this go? in my html (where I grab the string parameters?) – Becky Jun 25 '15 at 12:51
  • But in my question I've said `I'm grabbing the string value to be able to pass via jquery's $post() to a php` ? – Becky Jun 25 '15 at 12:56