April 5, 2012

echo plus sign php

Question by jose

I’m echoing a php string variable into html

<span class="title_resource">
  <?php echo  $titulo; ?>

But when the plus sign (+) is present, it turns into a space.

I’ve already tried using urlencode but then I get something like “Constru%25C3%25A7%25C3%”

Should I use something like string replace?

Thanks in advance


$titulo is setted using $_GET

if (isset($_GET['T']))// title
    $titulo = $_GET['T'];


More clear, perhaps

I want to send exactly this text “Estudo de ax^2 + bx + c”. The page receives by $_GET. When I print this value I get “Estudo de ax^2 bx c”

Answer by Starx

Its the way values as encoded to be sent over using GET, spaces are converted to + and + are converted to %2B.

If you really want to send the plus symbol over the form, then replace the spaces with plus

$text= str_replace(" ", "+", $text);

Next make sure your form uses correct enctype either application/x-www-form-urlencoded or multipart/form-data

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!