devknob Posted August 27, 2010 Share Posted August 27, 2010 function Clean_String($string) { return strtolower(trim(filter_var($string, FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW))); } Ive tracked my issue back to filter_var here. For some reason it is adding stuff to the beginning and end of the string im looking for. It did this on 1 string that I noticed and doesnt do it on any others, which was strange because that string was typical like all others. Just a few sentences and numbers and line breaks. I cant find a reason why this is happening Quote Link to comment https://forums.phpfreaks.com/topic/211895-filter_var-adds-crap-to-my-string/ Share on other sites More sharing options...
AbraCadaver Posted August 27, 2010 Share Posted August 27, 2010 What does this "crap" look like? Any of these? 	 Quote Link to comment https://forums.phpfreaks.com/topic/211895-filter_var-adds-crap-to-my-string/#findComment-1104422 Share on other sites More sharing options...
devknob Posted August 27, 2010 Author Share Posted August 27, 2010 It looked like it took ...random words from 2 other posts and put 1 before my string and 1 after. It was words and numbers. I went thru and debugged and got back to the filter_var. The string I am passing to Clean_String() absolutely does not contain this extra 'crap' - and I only get extra 'crap' when i leave filter_var in there. Quote Link to comment https://forums.phpfreaks.com/topic/211895-filter_var-adds-crap-to-my-string/#findComment-1104424 Share on other sites More sharing options...
AbraCadaver Posted August 27, 2010 Share Posted August 27, 2010 I'm not sure, try this: return strtolower(filter_var(trim($string), FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW)); Quote Link to comment https://forums.phpfreaks.com/topic/211895-filter_var-adds-crap-to-my-string/#findComment-1104426 Share on other sites More sharing options...
devknob Posted August 27, 2010 Author Share Posted August 27, 2010 ...the thing im scraping has posts posted and taken down all the time and the post is gona. like i said it worked fine until that post, which didnt have strange characters in it. This code works, ill replace my existing code and monitor for errors i guess lol. Guess I was also looking for an understanding of why Filter_Var would/could do something like this. I did not see anything in the documentation./ Quote Link to comment https://forums.phpfreaks.com/topic/211895-filter_var-adds-crap-to-my-string/#findComment-1104434 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.