Jump to content

delete the Space created after echo


Recommended Posts

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.

Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

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']);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.