How can I evaluate HTML depth in PHP? - php

I'm writing a PHP framework right now, and have run into somewhat of a formatting problem.
My intention is to load in a combination of a few files, compile them all together, and kick them out as their appropriate HTML. In this process, I intend to indent or outdent as I progress line to line. Right now, I use a combination of simple checks for '<', '&lt/' and '/&gt', ( Couldn't use the real character here ) alongside some XML parsing to achieve this, but I'm sure that there is a better way to do this.
Right now my code gives me something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Your Sitename - Module - Index</title>
<link rel="stylesheet" href="layout/layout/default/css/styles.css" type="text/css" />
<link rel="stylesheet" href="php/plugins/MoviePlayer/windows/IE/Silverlight/css/silverlight.css" type="text/css" />
<script type="text/javascript" src="js/Cookies.js"></script>
<script type="text/javascript" src="js/GlobalReady.js"></script>
<script type="text/javascript" src="js/PluginDetection.js"></script>
<script type="text/javascript" src="js/Silverlight.js"></script>
<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="js/jquery.flow.1.2.js"></script>
<script type="text/javascript" src="layout/layout/default/js/LayoutInit.js"></script>
<script type="text/javascript" src="php/plugins/MoviePlayer/windows/IE/Silverlight/js/SLPlayer.js"></script>
<script type="text/javascript" src="php/plugins/MoviePlayer/windows/IE/Silverlight/js/wmvplayer.js"></script>
</head>
<body onLoad="javascript: GlobalReady();">
<div id="container">
<div id="header">
</div>
</div>
</body>
</html>
Which is a little off of what I am trying to achieve.
I'm not any sort of regular expression expert; or user even, and I assume that I could achieve this in that manner, but wouldn't know how to go about it.
Effectively, my question is this; how would You approach formatting this properly ( programatically ), if you were printing it out one line at a time? Is there a library that could identify all of the elements on a single line, regardless of their association with a later element?
If not I'm sure I'll be writing a new class to handle this on my own.
I am trying to achieve something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Your Sitename - Module - Index</title>
<link rel="stylesheet" href="layout/layout/default/css/styles.css" type="text/css" />
<link rel="stylesheet" href="php/plugins/MoviePlayer/windows/IE/Silverlight/css/silverlight.css" type="text/css" />
<script type="text/javascript" src="js/Cookies.js"></script>
<script type="text/javascript" src="js/GlobalReady.js"></script>
<script type="text/javascript" src="js/PluginDetection.js"></script>
<script type="text/javascript" src="js/Silverlight.js"></script>
<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="js/jquery.flow.1.2.js"></script>
<script type="text/javascript" src="layout/layout/default/js/LayoutInit.js"></script>
<script type="text/javascript" src="php/plugins/MoviePlayer/windows/IE/Silverlight/js/SLPlayer.js"></script>
<script type="text/javascript" src="php/plugins/MoviePlayer/windows/IE/Silverlight/js/wmvplayer.js"></script>
</head>
<body>
</body>
</html>
Thanks ahead of time.

Load a few files, concatenate them into a string, and use tidy to format them.
However, it's most likely a problem with the code generating the HTML, that should be fixed instead of outputting malformed code and fixing it later.

Related

ckeditor can't access root directory IE9

I always have some problems with IE. The problem is that my website must work on every browser, including IE.
Everything works well for the ckeditor plugin named prgfilemanager (I can add pictures into my ckeditor textarea). Every browser are working except IE... I first succeed displaying ckeditor using
<meta http-equiv="X-UA-Compatible" content="IE=9.0">
Without that meta, the textarea isn't a ckeditor textarea.
My problem is that when I try to add pictures, nothing happens ONLY IN IE.
When I click to search pictures there is a popup with the interface with no root..
If i write http://XXX/ckeditor/plugins/pgrfilemanager/PGRFileManager.php?type=Image&CKEditor=Description&XXX everything works well on every browser except for IE..
I'm on IE9. How to make pgrfilemanager working on IE 9 ?
This is what IE gives me
I found how to make it work. As I said, I used <meta http-equiv="X-UA-Compatible" content="IE=9.0"> in my files to make ckeditor working. What to do if you have the same problem that I HAD, in ckeditor\plugins\pgrfilemanager, open PGRFileManager.php and add the meta <meta http-equiv="X-UA-Compatible" content="IE=9.0"> on the <head>. Like
<head>
<!-- ADD THIS -->
<meta http-equiv="X-UA-Compatible" content="IE=9.0">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>PGRFileManager v2.1.0</title>
<link rel="stylesheet" type="text/css" href="css/sunny2/jquery-ui-1.8.1.custom.css" />
<link rel="stylesheet" type="text/css" href="css/jquery.treeview.css" />
<link rel="stylesheet" type="text/css" href="css/fancybox/jquery.fancybox.css" />
<link rel="stylesheet" type="text/css" href="css/PGRFileManager.css" />
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.1.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.treeview.js"></script>
<script type="text/javascript" src="SWFUpload v2.2.0.1 Core/swfupload.js"></script>
<script type="text/javascript" src="js/jquery.i18n.js"></script>
<script type="text/javascript" src="js/jquery.fancybox-1.2.1.pack.js"></script>
<?php if (PGRFileManagerConfig::$ckEditorScriptPath):?>
<script type="text/javascript" src="<?php echo PGRFileManagerConfig::$ckEditorScriptPath ?>"></script>
<?php endif;?>
<script type="text/javascript" src="lang/lang.js"></script>
<script type="text/javascript" src="js/PGRUploader.js"></script>
<script type="text/javascript" src="js/PGRContextMenu.js"></script>
<script type="text/javascript" src="js/PGRSelectable.js"></script>
<script type="text/javascript" src="js/PGRFileManager.js"></script>
<script type="text/javascript" src="js/PGRFileManagerContent.js"></script>
</head>

LESS doesn't work at localhost Linux

I want to use LESS, but it is doesn't work at my localhost.
Here is my index.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; utf-8">
<link rel="stylesheet/less" type="text/css" href="styles.less">
<script src="less.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
and here is my styles.less
#nice-blue: #5B83AD;
body{
backgroud-color: #nice-blue;
}
You shouldn't be using your less files directly in your HTML. Less is a CSS pre-processor, and needs to be compiled in order to be read by your browser.
Follow the examples here (http://lesscss.org/) on how to compile your LESS file so that you can use the CSS.

Generate The DOM whit PHP

Is there a easy way or what is the best way for generating the DOM with PHP? I have read a little of PHP DOMDocument but I don't really understand it.
I would like to generate a simple HTML5 DOM start.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/>
<title>★ Site Title ★</title>
<link rel="stylesheet" href="css/style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="js/functions.js"></script>
</head>
<body>
</body>
</html>

HTML - Merge two head tags into one

I am trying to merge two html heads by php include()-ing a php file (which contain the header for reusability) into another. The code works but it results into this:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="./css/custom-theme/jquery-ui-1.10.3.custom.min.css">
<link href='http://fonts.googleapis.com/css?family=Noto+Sans' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="./js/jquery191.js" ></script>
<script type="text/javascript" src="./js/jqueryui1103.js" ></script>
</head><html>
<head>
<title>Add Employee Form</title>
<link rel="stylesheet" type="text/css" href="./css/addform.css">
<script type="text/javascript" src="./js/talentform.js" ></script>
<script type="text/javascript" src="./js/form_submission.js" ></script>
</head>
Which is I think against the standards. Is there a way of merging those two heads into one without violating the standards? By the way, I am using CodeIgniter 2 Framework, if it helps. Thanks!

Page only loads the last linked javascript file, also google font API stopped working

I'm programming a website in PHP 5 and for convenience I've elected to use includes for the header and footer on each page.
My html and head setup looks like this atm, and had been unchanged since I started
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html lang='en'>
<head>
<meta charset='utf-8'>
<!--[if IE]><![endif]-->
<title>TITLE</title>
<meta name='description' content=''>
<link href='http://fonts.googleapis.com/css?family=Droid+Sans:regular,bold&subset=latin' rel='stylesheet' type='text/css'>
<link rel='stylesheet' href='css/default.css'>
<link rel='stylesheet' href='css/bbeditor.css'>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
<script src="js/jQuery.js" type="text/javascript"></script>
<script src="js/bbeditor.js" type="text/javascript"></script>
</head>
As you can see I use some jquery, a nice simple bbeditor for user input and the google font api. What started happening was that I could only load the last mentioned javascript file for some reason, in this case, it would be the bbeditor. not only that, the font api just wont load at all.
I should mention that the CSS files load perfectly fine however.
Does anyone know what's going on?
Try using firebug's "Net" tab, it will show you all the requests and responses. Firstly check the Status column and, if something's wrong, the response.
Try closing your one-line tags:
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html lang='en'>
<head>
<meta charset='utf-8' />
<!--[if IE]><![endif]-->
<title>TITLE</title>
<meta name='description' content='' />
<link href='http://fonts.googleapis.com/css?family=Droid+Sans:regular,bold&subset=latin' rel='stylesheet' type='text/css' />
<link rel='stylesheet' href='css/default.css' />
<link rel='stylesheet' href='css/bbeditor.css' />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
<script src="js/jQuery.js" type="text/javascript"></script>
<script src="js/bbeditor.js" type="text/javascript"></script>
</head>
Note the /> at the end of link and meta tags.

Categories