![]() |
glitch in load->view usage - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: glitch in load->view usage (/showthread.php?tid=17937) |
glitch in load->view usage - El Forum - 04-20-2009 [eluser]TWP Marketing[/eluser] I'm getting a bug that I cannot track down. Three characters are appending to the front of a view segment. The Controller: Code: ... The model: Code: function build_view_content( $data ) The view simply echos $Cart_Display as a string of HTML code but it contains these three characters () appended to the front of the string contained in $Cart_Display: Code: ... This is the output HTML: Code: ... glitch in load->view usage - El Forum - 04-20-2009 [eluser]grisha[/eluser] Hello there. I assume that the first line of 'cart_display' is this one: Code: <a href="http://www.twpmarket.ing/index.php/twp/cart">Shopping Cart</a> If you're using UTF-8 encoding for your source files, try to use UTF-8 without BOM - three first bytes of each file encoded in UTF-8. Hope that helps. glitch in load->view usage - El Forum - 04-20-2009 [eluser]TWP Marketing[/eluser] Bingo, That was indeed the problem, thank you! I patched it with this code in the model Code: $data['Cart_Display'] = substr($this->load->view( 'cart_display', $Cart, TRUE ),3); Does anyone know if there is a more "elegant" solution to removing the BOM from UTF-8 output from load->view()? glitch in load->view usage - El Forum - 04-20-2009 [eluser]grisha[/eluser] Using substr is not a good solution. I would rather recommend you to set up your editor to use UTF-8 without BOM, and then open the file and just save it again. The same problem can occur in many other places. glitch in load->view usage - El Forum - 04-20-2009 [eluser]TWP Marketing[/eluser] I already did that, Notepad++ 2 allows BOM removal from UTF-8 encoding. However this occurs also when I take RSS downloads from (some) outside sources. My patch fixes them also. I'l have to apply it only where the problem occurs but I can live with that. It wasnt' clear from my posted code, but the cart_display variable was a generated html stream, not a static file, so opening and closing it with notepad++ isn't applicable... Thanks for your assist! [update 4/21] Notepad++ requires use of the 'format/convert' menu option to cause a file to be re-formatted to UTF-8 without BOM (and then it must be saved...). I had a mixture of actual CI view files, which did need to be reformatted without BOM and code generated view CONTENT which did not send the BOM to the server. Hence some of my pages showed the BOM on-screen and some did not. I reformatted my entire view directory and now the 'patch' above is not needed. In fact it caused problems since it removed code from the reformatted data stream. All is well now, thanks to your assistance! |