illusiveone Posted January 16, 2008 Share Posted January 16, 2008 hi guys, this is my first post on phpfreaks so be easy this is probably a stupid question, but lemme give you some background first. i just became webmaster for a web portal and the previous webmaster make all kinds of grammatical mistakes in his code. adding apostrophes where they shouldnt be, and misspelling just about everything that you couldnt sound out phonetically. ive been going through all the pages and fixing his (small) mistakes. but for some reason either im not seeing this or im too tired to realize what to change here.. <?=$data['fname']."'";?> <?if (substr($data['fname'],-1)!= "s") {echo "s";} else {echo "";} ?> this comes out as <username>' s comments with a space between the apostrophe and the s. again, very stupid problem, but a problem nontheless. if someone could point out my obvious oversight, i would be eternally grateful Quote Link to comment https://forums.phpfreaks.com/topic/86342-trying-to-remove-a-space-from-a-data-call-help/ Share on other sites More sharing options...
GingerRobot Posted January 16, 2008 Share Posted January 16, 2008 Firstly, welcome to the forums! I can't see anything wrong with that (apart from the general messy code). I can only assume that it is the the element of the array, $data['fname'], that has a space on the end of it. You could test that by comparing the length of the string and the string itself. <?php echo $data['fname'].' has a length of: '.strlen($data['fname']).'<br />'; ?> So, for example, if the first name is Ben, and the length of the string is 4, we know we have a rogue space in there. p.s. Try to remember to use the tags for your PHP code (and, where possible, full opening tags - we then get syntax hightlighting making it much easier to read) Quote Link to comment https://forums.phpfreaks.com/topic/86342-trying-to-remove-a-space-from-a-data-call-help/#findComment-441176 Share on other sites More sharing options...
illusiveone Posted January 16, 2008 Author Share Posted January 16, 2008 thanks for the suggestions, i used the string "checker" to find out how many characters it would return. using my account it returned 4 chars (my name is alan), which is correct so basically the space is somewhere after the variable. i cant seem to find that particular space in the code that was used. ??? Quote Link to comment https://forums.phpfreaks.com/topic/86342-trying-to-remove-a-space-from-a-data-call-help/#findComment-441209 Share on other sites More sharing options...
GingerRobot Posted January 16, 2008 Share Posted January 16, 2008 Ah, i got it. Change your code to: <?php echo $data['fname']."'"; if (substr($data['fname'],-1)!= "s"){ echo "s"; } ?> The space being generated wasn't being echoed by PHP, it was in the HTML. That happened because there was a space between closing the first bit of PHP and opening the second. Quote Link to comment https://forums.phpfreaks.com/topic/86342-trying-to-remove-a-space-from-a-data-call-help/#findComment-441232 Share on other sites More sharing options...
illusiveone Posted January 16, 2008 Author Share Posted January 16, 2008 hahahaha thanks i was gona reply and say that i figured it out too... <?php=$data['fname']?> <?if (substr($data['fname'],-1)!= "s") {echo "'s";} else {echo"";} ?> a little different, but the same end result. not the most beautiful thing out there, but it works thanks for all your help ginger, if youre ever in louisiana for mardi gras i owe you a beer! Quote Link to comment https://forums.phpfreaks.com/topic/86342-trying-to-remove-a-space-from-a-data-call-help/#findComment-441366 Share on other sites More sharing options...
revraz Posted January 16, 2008 Share Posted January 16, 2008 Change your other <? to <?php while you're at it. Quote Link to comment https://forums.phpfreaks.com/topic/86342-trying-to-remove-a-space-from-a-data-call-help/#findComment-441374 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.