markcunningham07 Posted July 16, 2010 Share Posted July 16, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/207906-delete-the-space-created-after-echo/ Share on other sites More sharing options...
Pikachu2000 Posted July 16, 2010 Share Posted July 16, 2010 What do you mean, exactly? There is a literal :space: after each line, or just that there is some space there in general? Quote Link to comment https://forums.phpfreaks.com/topic/207906-delete-the-space-created-after-echo/#findComment-1086846 Share on other sites More sharing options...
markcunningham07 Posted July 16, 2010 Author Share Posted July 16, 2010 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). Quote Link to comment https://forums.phpfreaks.com/topic/207906-delete-the-space-created-after-echo/#findComment-1086848 Share on other sites More sharing options...
Pikachu2000 Posted July 16, 2010 Share Posted July 16, 2010 rtrim($_GET['variable']) Quote Link to comment https://forums.phpfreaks.com/topic/207906-delete-the-space-created-after-echo/#findComment-1086852 Share on other sites More sharing options...
dezkit Posted July 16, 2010 Share Posted July 16, 2010 you should also use trim() incase there is an accidental space in the beginning Quote Link to comment https://forums.phpfreaks.com/topic/207906-delete-the-space-created-after-echo/#findComment-1086860 Share on other sites More sharing options...
markcunningham07 Posted July 16, 2010 Author Share Posted July 16, 2010 is it possible to trim something generate from echo PHP input : echo $_GET["fullname"]; Output: joe thomas is it possible to do something below to take out the space between joe and thomas Quote Link to comment https://forums.phpfreaks.com/topic/207906-delete-the-space-created-after-echo/#findComment-1086920 Share on other sites More sharing options...
Chud37 Posted July 16, 2010 Share Posted July 16, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/207906-delete-the-space-created-after-echo/#findComment-1086924 Share on other sites More sharing options...
markcunningham07 Posted July 16, 2010 Author Share Posted July 16, 2010 $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. Quote Link to comment https://forums.phpfreaks.com/topic/207906-delete-the-space-created-after-echo/#findComment-1086930 Share on other sites More sharing options...
joel24 Posted July 16, 2010 Share Posted July 16, 2010 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']); Quote Link to comment https://forums.phpfreaks.com/topic/207906-delete-the-space-created-after-echo/#findComment-1086933 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.