Jump to content

delete the Space created after echo


Recommended Posts

Hi,

Welcome <?php echo $_GET["firstname"]; ?>.<br />
Name<?php echo $_GET["Lastname"]; ?>.<br />
You are <?php echo $_GET["numer"]; ?> 

 

The result is below.

 

Welcome name .

Name chinna .

You are 45

 

There is space after every echo result.

how do i stop that space from generating.

 

Thank you

 

Link to comment
https://forums.phpfreaks.com/topic/207906-delete-the-space-created-after-echo/
Share on other sites

http://domain.com/flash/welcome.php?firstname=name+&Lastname=chinna+&numer=2336+

 

Just realize that space come from + sign on my URL

 

still looking for a way to delete it

 

Not that space.

 

what i mean is

on my example there are space after echo result.

 

name(space).

chinna(space).

45(space).

str_replace is a handy function.

 

$myVar = "One Space Two Space Three Space Four";

 

$x = str_replace(" ","",$myVar);

 

$x will output:

 

"OneSpaceTwoSpaceThreeSpaceFour"

 

Beware though, although there is a way, i havent managed to get it work nicely with words.  for instance:

 

$myVar = "I like to read the manual, man";

 

$x= str_replace("man","dude",$myVar);

 

$x = "I like to read the dudeual, dude".

 

There is a way but i couldnt be bothered to look into it at the time.

:)

 

hope that helps.

$myVar = "One Space Two Space Three Space Four";

 

is there is a way to change

One Space Two Space Three Space Four

to

echo $_GET["fullname"];

 

coz thats how i get the full name of the user

 

 

 

str_replace is a handy function.

 

$myVar = "One Space Two Space Three Space Four";

 

$x = str_replace(" ","",$myVar);

 

$x will output:

 

"OneSpaceTwoSpaceThreeSpaceFour"

 

Beware though, although there is a way, i havent managed to get it work nicely with words.  for instance:

 

$myVar = "I like to read the manual, man";

 

$x= str_replace("man","dude",$myVar);

 

$x = "I like to read the dudeual, dude".

 

There is a way but i couldnt be bothered to look into it at the time.

:)

 

hope that helps.

chud37, you'd use regular expressions in preg_replace() function to perform that task. I'm not all too good with regular expressions but this will work to find all instances of "man" with a space either side. '\s' denotes a space while '/' signifies the search string

i'm sure someone else could help to change the search expression so it searched for "man" with no alphabetic character next to it.

$myVar = "I like to read the manual, man";

$search = array("/\sman\s/");
$replace = array("dude");

$myVar = preg_replace($search, $replace, $myVar);

 

and markcunningham07,

you want to change $myVar to $_GET['fullname'] and remove spaces in it?!

i.e. $x = str_replace(" ","",$_GET['fullname']);

 

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.