ian2k01 Posted June 16, 2009 Share Posted June 16, 2009 Hello, I have a simple yet frustrating problem here. I'm on this project where it parses all customer information as variables then insert it into database, and aimed for paypal's transaction detail pages. When parsing the customer's name, there are 4 spaces between end of name and the closing </td> tag. so this is what the source code looks like: <tr valign="top"> <td align="right" class="label">Sent by:</td> <td><br class="textSpacer"></td> <td class="small">Annita Greuncuard </td> </tr> I have tried using str_replace to get rid of the " " with "", or preg_match_all here preg_match_all('~(.*) ~', $trMatches[1][0], $name); however, both results come back to be negative, and the database would read the " " as "Â Â Â Â ". Very frustrating. Any insight? Quote Link to comment https://forums.phpfreaks.com/topic/162476-unwanted-spaces/ Share on other sites More sharing options...
Alex Posted June 16, 2009 Share Posted June 16, 2009 Nevermind. Quote Link to comment https://forums.phpfreaks.com/topic/162476-unwanted-spaces/#findComment-857580 Share on other sites More sharing options...
Ken2k7 Posted June 17, 2009 Share Posted June 17, 2009 You're making this harder than it should be. First of all, use trim before you insert data into the DB so there won't be whitespaces afterwards. But trim would take care of the spaces for you. Quote Link to comment https://forums.phpfreaks.com/topic/162476-unwanted-spaces/#findComment-857744 Share on other sites More sharing options...
ian2k01 Posted June 17, 2009 Author Share Posted June 17, 2009 You're making this harder than it should be. First of all, use trim before you insert data into the DB so there won't be whitespaces afterwards. But trim would take care of the spaces for you. As you suggested, I have tried both trim and rtrim but it still gives me the same output, with 4 spaces at the end. Is there another way to do so? Quote Link to comment https://forums.phpfreaks.com/topic/162476-unwanted-spaces/#findComment-858096 Share on other sites More sharing options...
thebadbad Posted June 17, 2009 Share Posted June 17, 2009 The spaces could be non-breaking spaces ( ), so try to convert those to regular spaces and then trim() the string: $str = trim(str_replace(' ', ' ', $str)); Quote Link to comment https://forums.phpfreaks.com/topic/162476-unwanted-spaces/#findComment-858146 Share on other sites More sharing options...
ian2k01 Posted June 17, 2009 Author Share Posted June 17, 2009 The spaces could be non-breaking spaces ( ), so try to convert those to regular spaces and then trim() the string: $str = trim(str_replace(' ', ' ', $str)); This did not seem to do anything. I am quite sure that they are spaces, because any of the methods above seem to work only when I copy and paste out the result onto a new file. Quote Link to comment https://forums.phpfreaks.com/topic/162476-unwanted-spaces/#findComment-858175 Share on other sites More sharing options...
corbin Posted June 17, 2009 Share Posted June 17, 2009 If the database is reading them as "Â Â Â Â", they might not be space characters at all. Perhaps just your text editor is displaying them as space characters. Try looking at the file in a hex editor or something to make sure they're really spaces. Quote Link to comment https://forums.phpfreaks.com/topic/162476-unwanted-spaces/#findComment-858285 Share on other sites More sharing options...
thebadbad Posted June 17, 2009 Share Posted June 17, 2009 What corbin said If they were simple spaces, trim() would remove them (if they are at the start or at the end of the string, that is). What does a var_dump() on the string output? And also show us the string you run through. BTW, you could try to strip any whitespace (if it is whitespace at all) from the end of the string with this: $str = preg_replace('~\s*$~D', '', $str); Quote Link to comment https://forums.phpfreaks.com/topic/162476-unwanted-spaces/#findComment-858302 Share on other sites More sharing options...
Ken2k7 Posted June 18, 2009 Share Posted June 18, 2009 Post the output of var_dump($trMatches[1][0]); Quote Link to comment https://forums.phpfreaks.com/topic/162476-unwanted-spaces/#findComment-858535 Share on other sites More sharing options...
MadTechie Posted June 18, 2009 Share Posted June 18, 2009 Thats an encoding issue, check your using the same encoding on the MySQL as you are on the HTML pages Quote Link to comment https://forums.phpfreaks.com/topic/162476-unwanted-spaces/#findComment-858542 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.