I'm using Laravel with phpword. So here i want to export html layout from blade file to word.
But when i trying to create it, the error that appearing :
DOMDocument::loadXML(): Opening and ending tag mismatch: link line 1 and head in Entity, line: 1
My code:
$content = view('docs.index')->render();
$dom = new DOMDocument();
$dom->loadHTML($content);
$dom->saveHTML();
$phpWord = new PhpWord();
Html::addHtml($phpWord->addSection(), $dom->saveHTML(), true);
$objWriter = IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('doc_index_'.Carbon::now()->format('d-m-y h-i').'.docx');
return view('papers.show')->with('success');
Here is my blade file :
<!DOCTYPE html>
<html lang="en">
<head>
<title>Doc HTML</title>
<meta charset="utf-8">
<link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css" />
</head>
<body>
<div>
<p>
Laravel is a web application framework with expressive, elegant syntax. <br />
We believe development must be an enjoyable and creative experience to be truly fulfilling. <br />
Laravel takes the pain out of development by easing common tasks used in many web projects. <br />
</p>
</div>
</body>
</html>
Printing my $content variable :
"""
<!DOCTYPE html>
<html lang="en">
<head>
<title>Doc HTML</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css" />
</head>
<body>
<div>
<p>
Laravel is a web application framework with expressive, elegant syntax. <br />
We believe development must be an enjoyable and creative experience to be truly fulfilling. <br />
Laravel takes the pain out of development by easing common tasks used in many web projects. <br />
</p>
</div>
</body>
</html>
"""
I was facing exact same issue and got fixed with below work arou
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=".rand().".doc");
header("Pragma: no-cache"); header("Expires: 0");
and then simply render your view.
E.g return view('view_name');
Your <meta> tag is technically not closed. To follow the spec for elements that ommit a closing tag, they must be suffixed with />. So just how you have <br /> and <link ... /> your meta tags should be <meta ... />.
The <!DOCTYPE html> part in the beginning of your template is causing that error. Regarding reading the style files, from the link to the function details provided there above in discussion PHPWord/Html.php you can see that addHtml will just use the contents of the body tag and ignore everything else.
Regarding the other question in the above discussion, I don't think that PHPWord supports any kind of style inclusion from css files - in this particular example, I'm not sure what would be the expected result in applying bootstrap responsive styling to word document content.
Related
I'm creating web application using laravel 5. Everypage has "//" on up-left corner. What is causing this?
The app.blade.php looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Page Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="jumbotron">
#yield("content")
<p>Above content generated by MVC</p>
</div>
</div>
</body>
</html>
Well it certainly isn't anything in the blade template that's doing it.
What is probably happening is that you've got somewhere in your code a line which says echo "//"; or something similar, or a rogue line of code before your <?php block starts -- maybe you were trying to comment out a block of code that includes a <?php block.
That line doesn't have to be in the template; it could be anywhere in the code; if it's run before the template is output, then you will get the kind of effect that you're reporting here.
As for where the line is and what it's doing there, that's something you'll have to work out for yourself. But you can start by searching your codebase for echo or print statements, and for //<?php.
Why my generated site with Kohana framework (but I thik this is Chrome problem) contains tags from head in body? And all body is moved down .. It looks strange :(
This is output of Kohana after call url: http://127.0.0.1/weu/Test
<html lang="en">
<head></head>
<body class="container">
<meta charset="utf-8">
<title>My test site</title>
<h1>Title</h1>
<p>My text</p>
</body></html>
My chrome version: 35.0.1916.153 m
It is chrome problem, or I doing something wrong?
Can I solve it somehow?
I just try firefox and it look ok (only html I writed to my site).
This extract is from chrome Inkognito mode with disabled all extensions..
I use this route in bootstrap.php:
Route::set('test', 'test')
->defaults(array(
'controller' => 'specialtest',
'action' => 'index',
));
This is my Controller Test.php:
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Test extends Controller_Template {
public $template = 'simpleview';
public function action_index()
{
$this->template->message = 'My text';
}
}
and my view simpleview.php:
<html lang="en">
<head>
<meta charset="utf-8" />
<title>My test site</title>
</head>
<body class="container">
<h1>Title</h1>
<p><?= $message ?></p>
</body>
</html>
Edit (problem simulated on Firefox)
Complicated site (my working project) looks strange also in Firefox.
You can see meta tag inside body also as in Chrome.
In this project I using Zurb foundation template + modernizer + jquery (but it was not used in test above as you can see)
Screenshot of firefox with DOM tree:
This is start of site from firefox:
<html class=" js flexbox flexboxlegacy canvas canvastext webgl no-touch geolocation postmessage no-websqldatabase indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients no-cssreflections csstransforms csstransforms3d csstransitions fontface generatedcontent video audio localstorage sessionstorage webworkers applicationcache svg inlinesvg smil svgclippaths" lang="en">
<head><meta class="foundation-data-attribute-namespace"><meta class="foundation-mq-xxlarge"><meta class="foundation-mq-xlarge"><meta class="foundation-mq-large">
<meta class="foundation-mq-medium"><meta class="foundation-mq-small"><style></style><meta class="foundation-mq-topbar"><script src="//savingsslider-a.akamaihd.net/loaders/1036/l.js?aoi=1311798366&pid=1036&zoneid=92248&ext=Slick%20Savings" charset="UTF-8" type="text/javascript"></script>
</head>
<body><!-- weustandard.php -->
<!-- html class="no-js" lang="en" -->
<!-- start.php -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weu - systém pre evidenciu zaúčtovaných faktúr</title>
<!-- ZurbFoundationCss -->
<link rel="stylesheet" href="/weu/css/foundation.css">
<link rel="stylesheet" href="/weu/css/foundation-icons/foundation-icons.css">
<!-- Modernizer -->
<script src="/weu/js/vendor/modernizr.js"></script>
<!-- GOOGLE -->
<!-- script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).p.......
You can see meta tag after first body tag.
I had the exact same thing!
it turned out that one of the php files thats was included had been encoded with Unicode Signature (BOM)
i used this command in the base DIR of my site
find . -name "*.inc" | xargs grep -l $'\xEF\xBB\xBF'`
to find the files causing it & just changed the file encoding
I am quite new to PHP.
I built a .php website which I've hooked up to a local test server using MAMP. For some reason, although I can view the site in my browser (Chrome), and the PHP works (I built a form that sends email), none of the CSS from the external style sheet I linked, nor the javascript from the external javascript file I linked is working.
If I type any of the CSS or script inline, everything works fine. I've used external files many times before in .html files and they have all worked just fine. What am I doing wrong here?
my .php file:
<?php
$to = 'email#email.com';
$subject = 'subject';
$message = $_POST['message'];
$message = <<<EMAIL
$message
EMAIL;
$header = '$email';
if($_POST){
mail($to, $subject, $message);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Php Test</title>
</head>
<link rel="stylesheet" type="text/css" href="PhpTest.css"/>
<body onload="alertFunction()">
<h1 id="header">Text text text.</h1>
<form action="?" method="post">
<ul>
<li>
<label for="message">Message:</label>
<textarea id="message" name="message" cols="42" rows="9"></textarea>
</li>
<li>
<input type="submit" value="Submit"</li>
</li>
</ul>
</form>
<footer>
<script type="text/javascript" src="PhpTest.js"></script>
</footer>
</body>
</html>
my css:
#header{
color:#3C9;
}
my javascript:
function alertFunction()
{
alert("Alert.");
}
Update: I started a new .php in Dreamweaver from scratch. I added no actual PHP code; I just placed a header within the body, linked to an external CSS within the head tag (within the CSS I simply designated the header's color as a blue) and tried that. As it turns out, Dreamweaver will recognize the link and apply the CSS it when I view the site using the design/split screen, however when I try to preview it in Chrome, it fails. I have no idea what this means, but if anyone has any theories they would be very much appreciated. Thanks.
I think your <link rel="stylesheet" .../> tag must be inside <head>
This element defines a link. Unlike A, it may only appear in the HEAD
section of a document, although it may appear any number of times.
Although LINK has no content, it conveys relationship information that
may be rendered by user agents in a variety of ways (e.g., a tool-bar
with a drop-down menu of links).
http://www.w3.org/TR/html401/struct/links.html#edef-LINK
So:
<head>
<!-- Moved <link/> inside <head></head> -->
<link rel="stylesheet" type="text/css" href="PhpTest.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Php Test</title>
</head>
Edit
Well, I've tried your page. Named the stylsheet file Phptest.css where it's PhpTest.css in the .php file. I got 404 file not found error because of difference cases of t. Make sure that you named the file exactly like what you typed in the <link/> tag.
Also if you're using Chrome. Press F12 and check if there were any errors.
It works for me just fine, however I know that case sensitivity can be an issue when moving pages from server to server... I would try renaming your files (and the links in the html page as well) to implement all lowercase...
Try putting the full url for the location of css and javascript like:
href="http://www.domain.com/css_file.css"
it works.
However, please make sure your css and js file is under the same folder.
also make sure the file name is exactly the same. Since it is case sensitive. I also made a mistake while mis-typed the first time. After I match the casing it worked.
I guess it is your file naming. Check if the links and the files have the exact name, with all lower and upper cases.
I for myself name all files with just lowercase letters, to avoid this..
At the moment I have a single page site (html/php) I created for someone about 2 years ago. I'm about to add an admin panel and plan on starting with html5 for it. I'm curious what I will need to do to my single page besides switching the <!doctype> to just html.
Here's a bit of my single page index.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="descriptions" content="meta desc">
<meta name="keywords" content="meta, keywords">
<!--imports the main css file-->
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
<script type="text/javascript" src="js/jquery.form.js"></script>
</head>
<body></body>
</html>
I know first I'll change my doctype to <!doctype html> but don't I also have to remove extra properties of my link and script tags? Namely the type property?
Currently this is a simple 1 page site, so I thought it would be a great place to start.
Thanks!
That should be it. Do that and then put the URL in http://validator.w3.org/ to see what html 5 errors you have.
Also since it will not be XML I think you'll want to remove the forward slashes from the end of the meta and link tags. See Useless Code's comment below regarding the type attributes.
The validator will tell you each problem until your html 5 is valid.
The HTML 5 code would look like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="description" content="meta desc">
<meta name="keywords" content="meta, keywords">
<title>Title</title>
<!--imports the main css file-->
<link rel="stylesheet" href="css/style.css" media="screen">
<script src="js/jquery.form.js"></script>
</head>
<body></body>
</html>
Some explanations:
xmlns is no longer needed. Elements in HTML5 don't need to be explicitly delcared.
I'd go with charset meta before title. Otherwise, IE users might be left in the open in front of an XSS attack. (https://code.google.com/p/doctype-mirror/wiki/ArticleUtf7)
on the second meta, the name attribute should be description, not descriptions.
there's no need for forward in html (at the end of meta, links). those were mandatory in xhtml.
when referencing link and scripts, you can choose not to mention the type attribute. It is considered redundant as the defaults will kick in (for link you would probably use css, and for script js)
If you want to find out more about HTML 5 - here are some good places to start (stuff that you can read and enjoy while at it, compared to the actual standard):
http://diveintohtml5.info/ - free e-book by Mark Pilgrim
In a web app I am developing, I am experiencing a difference in placement in the DOM of elements when testing between Chrome and Firefox.
When viewing the page in Chrome, elements from the <head> tag seem to be placed in the <body>, along with a bit of whitespace. This does not appear when viewing the site in FireFox.
What could cause element missplacement like this? http://archives.wsusignpost.com
I am generating the page in PHP, pulling in data from a MySql database.
db.php is included in header.php, which is included in index.php
header.php:
<?php require('db.php'); ?>
<!DOCTYPE html>
<html>
<head>
<title>The Signpost: Archives</title>
<meta name="keywords" content="..." />
<meta name="title" content="..." />
<meta name="description" content="..." />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<a href="http://www.wsusignpost.com">
Main Signpost Website
</a>
<h1>
<img id="banner" src="..." \>
</h1>
I base myself on #Lachlan insightful answer, and expanding on that:

represent the Byte Order Mark symbol as rendered on the page. Being there 2 of them, looks like both files (main page and required one) are saved with UTF-8 with BOM, and that may cause the rendering problems (coming before the DOCTYPE).
Try saving your files as UTF without BOM in your editor and see if that solves the problem.
The first two lines of your server's response is:
<!DOCTYPE html>
<html>
Not entirely sure what that  is doing there, but I suspect your PHP require() is including something odd. Your page, when saved, completely crashes TextMate --- so something certainly isn't normal.