I'm using AMP with PHP and when I'm trying the AMP validator (ttps://validator.ampproject.org/) I get a couple of errors that do not make sense become of a BOM character at the beginning of my page.
Example:
URL: https://www.laurentwillen.be/gadgets/xiaomi-redmi-note-7-test-avis-et-prix/
I get the following error: (among others)
The mandatory attribute '⚡' is missing in tag 'html'
If you look at the source of this page, the attribute is there but when you use the AMP validator, there is a red dot appearing at the very beginning of my page.
If I add a letter at the very top of my code like this:
A
<?PHP
// my code goes here
?>
I see the red dot appearing before the letter which highlights that my code is not generating the issue. In Notepad++ I see that the encoding is set to UTF8.
Do you know how I could remove this so that I can work on the real AMP errors?
Thanks
Laurent
Related
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 a very weird problem where, if I send a header to the client that the content type is "application/json", then PHP will inexplicably add spaces to the beginning of the document. If I change the document type back to normal, the spaces are gone.
To make sure that its not the browser trying to pretty-print, I tried Curl'ing the site, and the same result was achieved.
The top one is with json content type, and bottom is with default.
$ curl https://*****.so/api/
{"success":false,"error":{"code":2,"message":"API access node not found"}}
$ curl https://*****.so/api/
{"success":false,"error":{"code":2,"message":"API access node not found"}}
The reason I want to solve this, is because many JSON parsers will break if the first symbol you pass to them isn't { because they are unable to parse spaces.
It is something in your PHP code that adds those spaces.
For example, your code might look like this:
<?php
echo 'something';
?>
This code makes PHP send three spaces before executing the PHP code.
So, you need to check all code outside <?php and ?> tags, and make sure there is no spaces 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.
<!DOCTYPE html>
This is the code.
How can I fix that?
I tested the HTML/CSS/JavaScript before integrating the code with Laravel.
Make sure your PHP files don't have the closing tags (?>). They might add whitespace to your HTML.
For more info, see the PHP docs:
If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.
You might also want to take a look at this post: Why would one omit the close tag?
I know this is few years late but for other people.
change the page encoding to UTF-8 without BOM and it will be solved.
I'm using more than one ampersand in my url, see my link below
http://www.theonlytutorials.com/video.php?cat=55&vid=3975&auth=many
When i try to validate in w3c validator it showed hundreds of error because of this & (ampersand).
After that i read some post in here and i got the solution too.
Instead of using (&) If i use (&) w3c validates fine.
But the problem now is in search Engine. Instead of taking (&). it is taking like the below link
http://www.theonlytutorials.com/video.php?cat=55&vid=3975&auth=many
if you copy paste the above link in the address bar it will take you to the wrong page!. Please help how can i solve it.
There must be an error in your code but since we cannot see any of it I think the most important bit is to understand why the W3C validator complaints about raw &.
The HTML syntax contains two basic elements: tags (e.g. <strong>) and entities (e.g. €). Everything else is displayed as-is.
Browsers are expected to ignore errors.
When you type unknown or invalid tags, the browser will do its best to guess and fix it (you are probably aware of that already):
<p>Hello <i>world</b>!</p>
... will render as:
<p>Hello <i>world</i>!</p>
But the same happens when you type an unknown or invalid entity. In your example, there are two invalid entities:
http://www.theonlytutorials.com/video.php?cat=55&vid=3975&auth=many
^^^^ ^^^^^
However, it works because the browser is clever enough to figure out the real URL. Only the validator complaints because it is a tool specifically designed to find errors.
Now, imagine I want to use HTML to write an HTML tutorial and I want to explain the <strong> tag. If I just type <strong>example</strong>, the browser will display example. I need to encode the < symbol so it no longer has a special meaning:
<strong>example</strong>
Now the browser displays <strong>example</strong>, which is precisely the content I want to show.
The same happens with your URL. Since & is part of the entity syntax, when I want to insert a literal & I need to encode it as well:
Barnes & Noble
... will render as Barnes & Noble. Please note that this is only a syntactic trick to insert plain text into a HTML document. Your document shows Barnes & Noble. to all effects, no matter how you encode it. So when you replace & with & in your URL, you are not changing your URL, you are just encoding it.
If search engines are spidering the wrong URL, that means you have actually changed your URL rather than just encoding it, so the source code is:
http://www.theonlytutorials.com/video.php?cat=55&vid=3975&auth=many
... and renders as:
http://www.theonlytutorials.com/video.php?cat=55&vid=3975&auth=many
This can happen, for instance, if you encode twice:
<?php
$url = 'http://www.theonlytutorials.com/video.php?cat=55&vid=3975&auth=many';
$url = htmlspecialchars($url);
$url = htmlspecialchars($url);
echo $url;
... or:
<?php
$url = 'http://www.theonlytutorials.com/video.php?cat=55&vid=3975&auth=many';
$url = htmlspecialchars($url); // Oops: URL is already encoded!
echo $url;
Seems that you made a typo error, it must be & not &amp;