PHP DomDocument behaving differently in CLI and Web Browser - domdocument

I 'm using the following code:
$doc = new DOMDocument();
$doc->loadHTML("<i><p><strong>From: fsong | #001</strong><br/>I hate you DomDocument :(.</p></i><br/>you'd be surprised<br/>");
echo $doc->saveHTML();
Running it in the CLI gets me
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
<i><p><strong>From: fsong | #001</strong><br>I hate you DomDocument :(.</p></i><br>you'd be surprised<br>
</body></html>
while running it through the web browser returns:
Warning: DOMDocument::loadHTML(): Unexpected end tag : i in Entity, line: 1 in /home/xx/www/test/topic_archiver_test.php on line 50
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
<i></i><p><strong>From: fsong | #001</strong><br>I hate you DomDocument :(.</p>
<br>you'd be surprised<br>
</body></html>
Now I realize nesting a (p) tag inside an (i) tag breaks HTML rules, but I'm not the one responsible for the HTML. For some reason the CLI mode returns the document like the original while the web page version closes the (i) tag early to keep the HTML well-formed.
Is there something in my php.ini configurations that is causing the difference in behaviours? I checked the official docs (http://www.php.net/manual/en/dom.configuration.php) and there doesn't seem to be any configuration files or settings for DomDocument.

Looks like for some reason it is trying to validate the HTML. I'm not getting any errors running php 5.3.5 and libxml 2.7.6.
One way to ignore the warning is prepending a '#' character, of course this is kind of a hack.
#$dom->saveHTML();

You could try turning off strictErrorChecking from DOMDocument

Related

Problem in printing a webpage containing SVG images in Chromium

I have a html file with the following content:
<html>
<body>
<object data="https://upload.wikimedia.org/wikipedia/commons/0/09/America_Online_logo.svg" type="image/svg+xml"></object>
</body>
</html>
As you can check, you can open it with chrome and print it.
But if I use Chromium.Print method, it print empty pages.
Note that this is only a sample. All SVG images had the same problem.
I use Delphi 10.3.2 and CEF4Delphi.
Can any one guide me?
This is very likely caused by the CEF issue #3297 and the workaround described in that report works.
Add this code line before the GlobalCEFApp.StartMainProcess call :
GlobalCEFApp.DisableSiteIsolationTrials := True;
I tested this workaround with the latest CEF4Delphi version which uses CEF 100.0.14 and the MiniBrowser demo. Your sample HTML is printed correctly with TChromiumCore.Print and TChromiumCore.PrintToPdf.

Change values in <head> of HTML in Angular Dart

so I am relatively new Angular Dart and Dart in general, and I am trying to create a simple webapp.
When I used to do PHP development I always had a config file that determined what environment the app was running on and decided to setup itself in different ways.
I am trying to figure how to achieve something similar in Angular Dart. Specifically as an example for the beginning I want to set different base href based on the URL that is loading the app. When you read the documentation it says that during development you should set the base href like this:
<script>
// WARNING: DO NOT set the <base href> like this in production!
// Details: https://webdev.dartlang.org/angular/guide/router
(function () {
var m = document.location.pathname.match(/^(\/[-\w]+)+\/web($|\/)/);
document.write('<base href="' + (m ? m[0] : '/') + '" />');
}());
</script>
But for distribution it should be set like this:
<base href="/">
All of this needs to be located in the <head> section of the HTML page so I would like to do some sort of an if statement here. Example how I wold do it in PHP:
<head>
<?php if(DEV) { ?>
// Do the development base href
<?php } else if(PROD) { ?>
// Do the production base href
<?php }?>
</head>
So my question basically is, is something like this possible in Angular Dart at the moment ?
You can't do binding in <head> with Angular.
I think there is still a way to pass "environment" variables to the app using -D=PROD=...
and then you could use const isProd = bool.fromEnvironment('PROD') (see also https://github.com/dart-lang/site-www/issues/404)
and then use dart:html to manipulate the DOM.
I haven't used this in web for a while and I'm not sure it's still supported in Dart 2.
(Update found https://github.com/dart-lang/build/issues/1053)
If '<base href="..."> is only for Angular routing, then it's better to use
import 'package:angular_router/angular_router.dart';
and adding
ValueProvider<String>.forToken(appBaseHref, '/'),
to Angular providers.
I'm also using a build script that copies files like
cp web/run_config_prod.dart web/run_config.dart
webdev build ...
cp web/run_config_dev/run_config.dart
to have some settings changed depending on the target environment.

invokescriptasync HRESULT: 0x80020101' script runs fine in chrome and IE

I'm still trying to make the invokescriptasync work. I'm trying the following test on facebook.com and it fails with a HRESULT: 0x80020101' which normally means the script has an error in it, but I tried running the simple javascript in Chrome and IE without any problem.
private async void WebView_OnNavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
await _webView.InvokeScriptAsync("eval", new[]
{
"document.getElementById('blueBarDOMInspector').innerHTML = '';"
});
}
Thanks
I have tested your code and the error is thrown only in case the blueBarDOMInspector is not found. I used the following simple HTML:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<p id="blueBarDOMInspector"></p>
</body>
</html>
You can confirm that the script works as expected with this HTML. So I suspect the problem is rather on HTML side than on side of UWP.
As for ScriptNotify not working - the website must be HTTPS and be added as trusted to appxmanifest. Better solution is web allowed object. A great example was posted in a question yesterday on SO or here as a sample project. Basically you have to create a Windows Runtime Component with a class marked as [WebAllowed] and then inject it in the WebView using AddWebAllowedObject method.
For your invoking JavaScript code issue,I've checked your code, it's simple, the possible issue might be the 'blueBarDOMInspector' object, please make sure that you could get the 'blueBarDOMInspector' object successfully when the OnNavigationCompleted is fired.
For your second question:
I can invoke the script : "window.external.notify('something');" but it doesn't raise the event ScriptNotify which is another problem :-(
Please check the document:
To enable an external web page to fire the ScriptNotify event when calling window.external.notify, you must include the page's Uniform Resource Identifier (URI) in the ApplicationContentUriRules section of the app manifest.

I have greek text on a String in Dart using Polymer, why is it displayed wrongly on the browser?

I have the following String on my Dart code, using Polymer:
#observable String title = "Καλώς Ήρθατε Ξανά!";
But this is what I see on the browser:
Καλώς ΉÏθατε Ξανά!
What am I missing ?
When the text uses the regular Latin chars, everything is perfect.
Thank you in forward
Try this:
Import:
import 'dart:convert' show UTF8;
Code:
List<int> encoded = UTF8.encode('Καλώς Ήρθατε Ξανά!');
#observable String title = UTF8.decode(encoded);
Short Code:
#observable String title = UTF8.decode(UTF8.encode('Καλώς Ήρθατε Ξανά!'));
This should encode your string as UTF8 so it shows up properly on screen.
I had the same issue with French.
Set the charset into your HTML file header (default is ISO-8859-1)
Short:
<meta charset="utf-8">
Long:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
This should solve this issue. BTW all strings in Dart are already in UTF8
Like #Akshay comments on his response:
It must be a bug in Dartium, I found this:
code.google.com/p/dart/issues/detail?id=14948
I ran it as JS and the greek String was displayed properly. (With out the need of any Encoding or else, just with the String).
So, I ran the JS version on the Chromium browser just to check... maybe it was a Browser issue.... but it ALSO WORKED!
The solution is: There is no solution... IT's a bug on the Dartium, (see link above).

Firefox / Safari not storing any offline cache data

Given the following appcache-manifest :
CACHE MANIFEST
#offline.manifest
#version 1.0 3-18-20141
CACHE:
offline.php
NETWORK:
*
FALLBACK:
* offline.php
And two simple php-files :
<!DOCTYPE html>
<html lang="de" manifest="offline.manifest">
<body>Offline, ohooohoo!
</body>
</html>
and:
<!DOCTYPE html>
<html lang="de" manifest="offline.manifest">
<body>Online, sucks!
</body>
</html>
I neither can get Firefox, nor Safari on IOS to work offline correctly. The manifest-file is delivered with the correct MIME-Types:
AddType text/cache-manifest .appcache
AddType text/cache-manifest .manifest
I'm quite amused that Firefox nor Safari is working, but Chrome. Using the about:cache?device=offline Option in Firefox, i get the following respoonse :
http://localhost/HTML5_SDK/offline.php 0 bytes 8 2014-03-18 17:34:49 2014-03-18 17:34:49
Which frankly means that a) my file is size zero and b) is expired as delivered.
I am freaking around with that stuff the whole day, and already did many nasty things as complety reinstalling the browser, killing mit Iphone with a brand new iOs and so on.
Chrome tells me that the offline.php is stored as FALLBACK EXLIPCIT with 465b, which matches.
Did anybody already manage to really get an offline-manifest with fallback working crossplattform-wide?
thanks for your adviced and best regards
Florian
You cant use a wildcard in the Fallback section. This must be a URL pattern and might be enough to ruin the day for your browser.
You can achieve the same thing by specifying root.
FALLBACK:
/ offline.php
Lastly, if one of those php pages is offline.php then this does not need to be added to your CACHE: section because you have explicitly requested it in the html tag. From my experience it shouldnt hurt though.
I've found exactly the same thing as this. And discovered that Firefox is really picky about the HTTP headers that the webserver sends back.
I was setting back a Cache-Control: no-store header (on the Manifest), which Chrome happily accepted, but Firefox errored silently with showing the 0 bytes stored that you reported.
This one change got it all working for me.

Resources