I am getting 8 lines inserted at the beginning of each page in codeigniter framework, is it something with the framework and how do i remove these lines. I have tried to use hooks to minify html but i cant seem to remove the new lines inserted.
Found the answer from How do you remove a leading newline in output to browser in Codeigniter. The issue was new lines after php closing tag "?>" in one of my modules.
Related
I have a function called getContents(), Which accepts a regex for the file names it finds.
I scan the js folder for javascript files, with the following two regex patterns:
$js['head'] = "/(\.head\.js\.php)|(\.head\.js)|(\.h.js)/";
$js['foot'] = "/(\.foot\.js\.php)|(\.foot\.js)|(\.f.js)|(\.js)^(\.head\.js)/";
I have a naming system whereby if you determine where the javascript file gets loaded, in the <head> tag or footer of the HTML page. All files are generally considered to be loaded at the bottom of the page, unless you specify (.head.js for example).
Up until a few days a go I noticed that the js['foot'] array was also including .head.js as well, causing the files to be loaded twice. So I added in the ^(\.head\.js) and it worked! it stopped the .head.js files being added into the footer array. I was quite pleased with myself, because I suck at regex. However it seems now that standard .js files (any normal .js files) arnt being loaded into the $js['foot'] array now. Why is this? If I remove the ^(\.head\.js) part it loads them.
To be clear, I want the $js['foot'] array to load files ending with:
.foot.js.php
.foot.js
.f.js
.js
And IGNORE all:
.head.js.php
.head.js
.h.js
Can someone correct my regex above to do this? I thought the ^ operator was NOT but i was wrong!
^(\.head\.js) in the middle of string makes it an invalid because ^ is considered anchor that matches line start.
You actually need a negative lookbehind assertion to stop matching head.js in footer regex:
$js['head'] = '/\.head\.js(?:\.php)?|\.h.js/';
$js['foot'] = '/\.foot\.js(?:\.php)?|(?<!head|h)\.js/';
RegEx Demo
All my wordpress websites have recently been hacked, and a very long PHP line has been added on top of all PHP files.
It looks like that (juste a sample of the entire code)
<?php $gqmtlkp = '~ x24<!%o:!>! x242178}527}88:}35csboe))1/35.)1/14+9**-)1/2986+7452]88]5]48]32M3]317]445]212]445]43]321]y]252]18y]#>q%
The problem is that code is generated and is different in all files. But I noticed that every code contains
explode(chr((729-609))
Can someone help me with building a regex line, that will target first php tag (optional) containing : (numbers vary)
explode(chr((xxx-xxx))
so that I can automatically remove it in every files ?
Thanks a lot for your help
Based on my understanding of your request you're looking to escape the following format: <?php(optional) explode(chr((xxx-xxx))) <- your sample was missing a third closing paranthesis for explode() function so I added it. If that's not right then just remove the last \) portion.
Try this: /(\<\?php)? explode\(chr\(\([0-9]{3,3}-[0-9]{3,3}\)\)\)/
Not sure if space after optional first php tag is necessary. You can adjust it going from there.
I have noticed that i have 2 or 3 line breaks on each page source code before any content.
I checked utf-8 BOM on my some files but they are ok, i use netbeans so normally no problem no ?
Maybe some parent output or controller in CI is making it ?
These line breaks are breaking some servies requests ...
If you have any idea ...
Check that none of your helpers, controllers, libraries or models contain a php end tag (?>) after the content as any whitespace there could be outputted.
If you can't locate the whitespace source, you could change the output file in the codeigniter core (system/core/Output.php). Locate the _display function, in that function before the check for compression, add: $output = trim($output);. In CI 2.1.4, this would be added at line 370. This will trim any whitespace from the start and end of your output.
I've been struggling with this problem for a long time now, but I cannot really find the solution. The problem is that < !DOCTYPE html etc... does not start at the first line, but leaves four blank lines before it starts.
All my files (header.php, index.php etc) have no line breaks before they start.
Anyone with any similar problems/experiences out there? It would have been of huge help!
See here for reference: view-source:http://2famous.tv/
Thank you
This is most often not caused by leading but by trailing whitespace. Lots of old PHP code still closes down code at the end, which then all too often has a stray newline:
<?php
// Lot of source code
?> <----- and a newline here which is the culprit!
To avoid this issue, never close files with ?> - PHP doesn't need it and will just stop parsing at EOF, thus implicitly avoid this 'garbage' in the output.
As for finding the files causing it - good luck, I'd start with combing any custom extensions for this and just removing all ?> markers that you can find.
As an alternative, you can probably 'fix' it by adding a single ob_start() call to your index.php, and then in the template containing the doctype executing ob_end_clean() - this puts all intermediate output in the output buffers, and then trashes it.
I'm having an issue, which seems like a bug, whereby if I download a CSV that I've created it seems to leave 12 empty spaces on the top of the file before filling in the content I want in there.
Is this just a general bug?
I'm using Codeigniter 2.1.3
Thanks Guys
I just had this same issue. When I looked through my code I was calling in a model that had a closing ?> tag, and for some weird reason, that created the extra space. Look to see if you have any closing php tags.
i had the issue too. But i solve it not related to closing ?>, but space in the beginning of php file. use tools such as winHex to open related php files, look if the file start with a space(in Hex it's 20), remove it, and the problem had solved.
sorry for my poor english.