Jump to content

php converting blank spaces to + symbol


php_begins

Recommended Posts

hello. I need some help here.

 

I have dynamic variable that contains characters separated by blank spaces. I need to replace the blank space (%20) with a plus(+) sign) wherever it occurs.

For example, my variable  $label might contain

$label=one word.

when i echo $label it prints one%20word. I would like to print it as one+word.

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/242795-php-converting-blank-spaces-to-symbol/
Share on other sites

That's pretty much why I asked. %20 is really only used in urls. If you are manually setting that, you are making more work for yourself. You should use urlencode on variables when sending them to the browser.

 

http://php.net/manual/en/function.urlencode.php

 

Then if you need to decode a url: http://www.php.net/manual/en/function.urldecode.php

 

Although for the most part you shouldn't ever have to use urldecode.

 

Example of urlencode:

 

<?php
   $variable=urlencode("my variable data & info");
   echo "<a href=\"url.php?variable={$variable}\">Go!</a>";
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.