Chrome loading the contents of a PHP file into a CSS file - php

My website loads perfectly on Firefox, but the CSS disappears completely on Chrome (although the html loads).
According to the console, this seems to be because Chrome is loading the contents of index.php into main.css and bannerTest.css like so:
On Firefox, however, it loads the CSS as expected:
Things I have tried that did not work:
clearing my history/cache/cookies
adding text/css to the tags. All this did was make the text render a
little weirdly on Firefox.
css and html validation. I fixed all the semi-colons and such. Still doesn't work.
What's the problem? I can't even figure out what steps to take to investigate what's going on more deeply, let alone figure out the problem itself. No errors are printed to the console as far as I can tell.
Here is index.php:
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Study</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="css/bannerTest.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
<link href="css/main.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"></script>
<style>
/**
* The banner assumes a margin of 0px, but is not included
* in banner.css to avoid collisions with other themes and
* admin bars.
*/
body {
margin:0px;
}
</style>
<link rel="icon" type="image/ico" href="favicon.ico">
</head>
<body>
<?php
//Connect to MySQL database.
$host = "127.0.0.1";
$user = "root";
$password = "password";
$database = "database";
$r = mysql_connect($host, $user, $password);
if (!$r) {
echo "Could not connect to server.\n";
trigger_error(mysql_error(), E_USER_ERROR);
}
$query = "CREATE DATABASE IF NOT EXISTS " . $database;
mysql_query($query);
#mysql_select_db($database) or die("Unable to select database.");
$query="CREATE TABLE IF NOT EXISTS `groupcodes` (`groupcode` int(10) PRIMARY KEY, `usercode` int(10))";
mysql_query($query);
$userid = "";
?>
<div id="banner">
<div id="u-header-container">
<div class="container">
<div class="row-fluid">
<div id="home-link-container">
<a id="home-link" href="http://csue.edu/">
<span id="wordmark">U</span>
<span id="university">UNIVERSITY</span>
</a>
</div>
</div>
</div>
</div>
<div id="database-container">
<header>
<a href="index.php">
<h4 id="logo">Computing Systems</h4>
<h1 id="study_logo">Study</h1>
</a>
</header>
<div id="study">
<form method="post" id="consent-form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="wide-column">
<p>
By clicking the 'Acccept' button below, you hereby acknowledge the following:
</p>
<p>
I am 18 years of age or older, live in the United States, and have a Google Drive or Dropbox account.
I have read this form and decided that I will participate in the project described above.
Its general purposes, the particulars of involvement, and possible risks and inconveniences have
been explained to my satisfaction. I understand that I can withdraw at any time.
</p>
</div>
<input type="text" name="email_input">
<br>
<input type="submit" value="Begin Study">
</form>
</div>
</div>
</div>
</body>
</html>

You misdiagnosed the problem. It is due to visiting different URLs to load the HTML document rather then using different browsers. You just switched browsers at the same time as you switched URLs.
Look at the URL that is being loaded in your first image:
http://localhost/peergroup/index.php/css/main.css
In Chrome you must be visiting http://localhost/peergroup/index.php/ while in Firefox you are visiting http://localhost/peergroup/index.php (without a / at the end).
This is causing relative URLs to be computed differently.
A workaround is to use URLs that are relative to the site root (i.e. starting with a /).

Related

I am attempting to create a php search bar that directs to larger search engines. It isn't working and I don't understand how to solve it.

webdevprocess.html
[This page is used solely for the search bar at the bottom of the page. Any search term can be entered and then a search engine can be selected from the drop down menu.]
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Web Development Process</title>
<meta name="Web Development Process" content="Simple Responsive Template is a template for responsive web design. Mobile first, responsive grid layout, toggle menu, navigation bar with unlimited drop downs, responsive slideshow">
<meta name="keywords" content="">
<!-- Mobile viewport -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<!-- CSS-->
<!-- Google web fonts. You can get your own bundle at http://www.google.com/fonts. Don't forget to update the CSS accordingly!-->
<link href='http://fonts.googleapis.com/css?family=Droid+Serif|Ubuntu' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="js/flexslider/flexslider.css">
<link rel="stylesheet" href="css/basic-style.css">
<!-- end CSS-->
<!-- JS-->
<script src="js/libs/modernizr-2.6.2.min.js"></script>
<script type="text/javascript" src="mypiechart.js"></script>
<script type="text/javascript" src="canvasjs.min.js"></script>
<!-- end JS-->
</head>
<body>
<body id="home">
<!-- header area -->
<header class="wrapper clearfix">
<div id="banner">
<div id="logo"><img src="images/logo.jpg" alt="logo"></div>
</div>
<!-- main navigation -->
<nav id="topnav" role="navigation">
<div class="menu-toggle">Menu</div>
<ul class="srt-menu" id="menu-main-navigation">
<li class="current">Home page</li>
<!-- <li>Internal page demo</li> -->
<li>Client/Server Technology
<ul>
<li>
Client/Server Technology
</li>
<li>Domain Names and Hosting</li>
</ul>
</li>
<li>
JavaScript Pages
<ul>
<li>Web Development Process</li>
</ul>
</li>
<li>
PHP Pages
</li>
</ul>
</nav><!-- end main navigation -->
</header><!-- end header -->
<!-- main content area -->
<div id="main" class="wrapper">
<!-- content area -->
<section id="content" class="wide-content">
<div class="row">
<h1>What Is The Web Development Process?</h1>
<p>A web development process,or web design and development process, is a systematic process or methodology, used tp desgn and build web sites. Just as planing goes into the design
of cars, buildings, or homes, so too is the planning and design and development process required for web sites. A good process helps ensure customer requirements are delivered in a quality
, timely and cos-effective manner.</p>
<h1>SDLC and Project Management</h1>
<p>The web design and development process can be thought of as a type of software development life cycle (SDLC) and project management methodology. The waterfall model depicted
below is a long-standing, traditional SDLC that is characterized by sequential steps. Agile is a newer method that is intended to more quickly respond to changing customer and
product requirements using an incremental process with frequent releases and customer feedback.</p>
<h3>Traditional Waterfall SDLC Methodology (PNG image)</h3>
<p><img src="waterfall.png" alt="Waterfall SDLC"></p>
<p>Source: WikiPedia</p>
<h3>Agile Methodology (GIF image)</h3>
<p><img src="images/agile.png" alt="Agile Methodology"></p>
<h3>Web Development Phases (HTML/JavaScript image)</h3>
<div id="chartContainer" style="height: 450px; width: 95%;"></div>
<script>
window.onload = function() {
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
title: {
text: "Web Development Process"
},
data: [{
type: "pie",
startAngle: 240,
yValueFormatString: "##0.00\"%\"",
indexLabel: "{label} {y}",
dataPoints: [
{y: 20.00 , label: "Testing"},
{y: 10.00, label: "Promotion"},
{y: 25.00, label: "Analysis"},
{y: 20.00, label: "Design"},
{y: 25.00, label: "Construction"}
]
}]
});
chart.render();
}
</script>
<br>
<form action="search.php" method="get">
<table>
<tr>
<th colspan="2">Search Sites</th>
</tr>
<tr>
<td>Site to Search:</td>
<td>
<select name="site">
<option value="google">Google Web
<option value="googlei">Google Images
<option value="duck">DuckDuckGo
<option value="wiki">WikiPedia
</select>
</td>
</tr>
<tr>
<td>Search term(s):</td>
<td>
<input type="text" name="terms" size="25" maxlength="25">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Submit" class-"centercell">
</td>
</tr>
</table>
</form>
<br>
</div><!-- end row -->
</section><!-- end content area -->
</div><!-- #end div #main .wrapper -->
<!-- footer area -->
<footer>
<div id="colophon" class="wrapper clearfix">
Author: Janae Roland
</div>
<!--You can NOT remove this attribution statement from any page, unless you get the permission from prowebdesign.ro--><div id="attribution" class="wrapper clearfix" style="color:#666; font-size:11px;">Site built with Simple Responsive Template by Prowebdesign.ro</div><!--end attribution-->
</footer><!-- #end footer area -->
<!-- jQuery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.9.0.min.js">\x3C/script>')</script>
<script defer src="js/flexslider/jquery.flexslider-min.js"></script>
<!-- fire ups - read this file! -->
<script src="js/main.js"></script>
</body>
</html>
search.php
[This program is supposed to send the search terms entered to large search engines (google,google images,duck duck go,wikipedia) but I am receiving a syntax error, "
Notice: Use of undefined constant FIlTER_SANITIZE_STRING - assumed 'FIlTER_SANITIZE_STRING' in /home/jsroland/public_html/search.php on line 13
Warning: filter_input() expects parameter 3 to be long, string given in /home/jsroland/public_html/search.php on line 13"]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="keywords" content="Rock,Paper,Scissors">
<meta name="description" content="A function that sends data to large search engines,through the WebDev search bar.">
<link rel="stylesheet" href="style.css" type="text/css">
<title>Search</title>
</head>
<body>
<?php
$site = substr(filter_input(INPUT_GET, 'site', FIlTER_SANITIZE_STRING),0,8);
$terms = substr(filter_input(INPUT_GET, 'terms', FILTER_SANITIZE_STRING),0,25);
if ($site == "google")
header('Location: http://www.google.com/#g=' . $terms);
else if ($site == "googlei")
header('Location: http://www.google.com/search?tbm=isch&g=' . $terms);
else if ($site == "duck")
header('Location: https://duckduckgo.com/?q=&ia=web' . $terms);
else if ($site == "wiki")
header('Location: https://en.wikipedia.org/wiki/' . $terms);
?>
</body>
</html>
The minimal correct urls for search engines would be as follows:
for general Google search: https://www.google.com/search?q='<search
terms>',
for Google image search:
https://www.google.com/search?tbm=isch&q='<search terms>',
for
DuckDuckGo: https://duckduckgo.com/?ia=web&q='<search terms>',
for
Wikipedia: https://en.wikipedia.org/wiki/<search terms>.
where <search terms> are the terms to search for.
Please also mind quotation marks in the first three cases. The final code would look something like this.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="keywords" content="Rock,Paper,Scissors">
<meta name="description" content="A function that sends data to large search engines,through the WebDev search bar.">
<link rel="stylesheet" href="style.css" type="text/css">
<title>Search</title>
</head>
<body>
<?php
$site = substr(filter_input(INPUT_GET, 'site', FIlTER_SANITIZE_STRING),0,8);
$terms = substr(filter_input(INPUT_GET, 'terms', FILTER_SANITIZE_STRING),0,25);
if ($site == "google")
header("Location: https://www.google.com/search?q='$terms'");
else if ($site == "googlei")
header("https://www.google.com/search?tbm=isch&q='$terms'");
else if ($site == "duck")
header("Location: https://duckduckgo.com/?ia=web&q='$terms'");
else if ($site == "wiki")
header("Location: https://en.wikipedia.org/wiki/$terms");
?>
</body>
</html>

How to do <title> dynamic in PHP

I have a little template and in this template I have a query from database.
The name of the page is test.php and the code is:
This is the main page where i echo the content is named test.php
<?php include "components/header.php"; ?>
<div class="container">
<!-- Jumbotron -->
<?php
if (isset($_GET['user']))
{
$user = $_GET['user'];
}
else
{
die("Not found");
}
$result = mysqli_query($con, "SET NAMES utf8");
$query = "SELECT * FROM users WHERE fk_music=".$user;
$res = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($res);
echo $row['text'];?>
</div>
<?php include "components/footer.php"; ?>
Now with the echo $row['text'] I have to echo all the content from the page, and in header.php are the data like <html><header><title></title></header> etc. How can I put a title foreach data from database dynamic?
There is the code from header.php
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>???</title>
<!-- Bootstrap core CSS -->
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="http://getbootstrap.com/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<link rel="stylesheet" href="/css/media-queries.css">
<link rel="stylesheet" href="/style.css">
<!--Hover categorii -->
<script src="/js/hover.js"></script>
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="/../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="http://getbootstrap.com/assets/js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
Now in database i have two rows id of the post and the row named text where is stored the HTML of all the page
Here is an example with content existing in row['text']
<p class='style-title'>HERE IS THE THE TEXT I WANT TO PUT IT IN <title> </p>
<div class='jumbotron'>
<img class='img-responsive' src='/img/img.png'/>
</div>
<div class='row'>
<div class="col-lg-10 ">
<img class='img-responsive' src='/img/50.png' align='left' />
<p class='some-class'>Lorm ipsum</p>

IE8 & Respond.js - Included Dynamic CSS Not Applying

I'm having some trouble with IE8 recognising some CSS that is generated from a PHP file and then included in my sites header. This CSS works perfectly in all other browsers I've tested but it simply won't apply in IE8.
If I move the dynamic CSS into my main css files - it works fine.
By dynamic, I mean the the CSS is generated from PHP. I'm already using respond.js to enable media queries in IE8 which is working because if I put this CSS in my main file - the CSS works.
However, if I put non-media query styles in the same file - it does apply. So this must be an issue with respond.js not seeing that responsive CSS.
When I 'View Source' the file has definitely included as it's printed in there but for some reason IE8 won't apply the styles. It doesn't show in Developer Tools.
Basically, the CSS should display a black menu bar at the top of the page when the browser window is narrower than 782 pixels.
You can see the full thing at: http://sandbox.benpalmer.me/flow/test/
The head of my document looks like this (this is a Wordpress theme/template):
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7 <?php if($theme_settings['modernizr-version'] != 'none'): echo 'no-js'; endif; ?>"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8 <?php if($theme_settings['modernizr-version'] != 'none'): echo 'no-js'; endif; ?>"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9 <?php if($theme_settings['modernizr-version'] != 'none'): echo 'no-js'; endif; ?>"> <![endif]-->
<!--[if IE 9]> <html class="no-js lt-ie10 <?php if($theme_settings['modernizr-version'] != 'none'): echo 'no-js'; endif; ?>"> <![endif]-->
<!--[if gt IE 9]><!--> <html class="<?php if($theme_settings['modernizr-version'] != 'none'): echo 'no-js'; endif; ?>"> <!--<![endif]-->
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title><?php wp_title( '|', true, 'right' ) . bloginfo('name'); ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1"> <?php
wp_head();
include(locate_template('assets/css/dynamic.css.php')); ?>
<!--[if lt IE 9]> <?php
if($theme_settings['modernizr-version'] == 'none'): ?><script type="text/javascript" src="<?php echo get_template_directory_uri() ?>/assets/js/vendor/modernizr.min.js"></script><?php endif; ?>
<script type="text/javascript" src="<?php echo get_template_directory_uri() ?>/assets/js/vendor/selectivzr.min.js"></script>
<script type="text/javascript" src="<?php echo get_template_directory_uri() ?>/assets/js/vendor/respond.js"></script>
<![endif]-->
</head>
<body <?php body_class(); ?>>
The include(locate_template('assets/css/dynamic.css.php')); file that is being included is set up like this:
<?php
/*
| --------------------------------------------------------------------
| Primary Navigation
| --------------------------------------------------------------------
*/
/* Breakpoint
| -------------------------------------------------------------------- */ ?>
<style type="text/css">
#media all and (max-width: <?php echo get_theme_mod('nav-primary-breakpoint', '782px'); ?>) {
#wrapper {
margin-top: 42px;
}
.admin-bar #wrapper {
margin-top: 88px;
}
#mobile-header {
display: block;
}
#menu-primary {
display: none;
}
.drawer {
margin-top: 42px;
padding-top: 42px;
top: -42px;
}
}
</style>
This one has me stumped - I've been Googling for an hour which brought up suggestions of changing my DOCTYPE, making sure my comments are ended properly etc but nothing has worked so far.
I suppose that by "dynamic CSS" you mean CSS media queries. If so, the answer is very simple:
IE8 does not support media queries.
There are some JS polyfills that solve the issue, the most famous one is perhaps respond.js.
EDIT
From the discussion in comments: It seems that the issue is caused by the fact, that Respond.js can read CSS from linked stylesheets only, not from inlined CSS.

PHP Includes and Require not working

I know this question has been asked before, but even after reading other posts I can't figure out whats going on...
Please have a look at my code structure and see what am I doing wrong..
Folder structure:
index.php
(FOLDER - Includes) header.php
(FOLDER - browse) blog.php , ecommerce.php, other.php
(FOLDER - core) init.php
I'm trying to include Header.php from includes folder in blog.php in browse folder. Below is my header.php code.
Header file located in Includes folder
<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
<head>
<!-- Basic Page Needs
================================================== -->
<meta charset="utf-8">
<title>Web Awwards | Web Gallery | Submit your site</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Mobile Specific Metas
================================================== -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!-- CSS
================================================== -->
<link rel="stylesheet" type="text/css" href="../css/base.css">
<link rel="stylesheet" type="text/css" href="../css/skeleton.css">
<link rel="stylesheet" type="text/css" href="../css/layout.css">
<link rel="stylesheet" type="text/css" href="../css/styles.css">
<link rel="stylesheet" type="text/css" href="../css/menu.css">
<link rel="stylesheet" type="text/css" href="../css/submission.css">
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Favicons
================================================== -->
<link rel="shortcut icon" href="images/favicon.ico">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
</head>
<body>
<?php
require_once('core/init.php');
?>
<!-- Menu Horizontal -->
<div class="horizontal">
<div class="webName">
and Browse folder blog.php file code:
<?php
include './includes/header.php';
?>
<!-- TODO PHP Scripts -->
<div class="category nine columns">
<div class="category-img">
<img src="css/img/webImg/screen1.png" alt="Site Description"/>
</div>
<h3> Web Name </h3>
<h5> Designed By: Tautvydas Slegaitis </h5>
<h7> Designers url </h7>
<div class="vote">
<h4> Vote for my site </h4>
</br>
Love it
Nope, Not for me
</div>
</div>
</div><!-- Close Container Div -->
<div class="footer">
</div>
</body>
</html>
But it is not working. I dont know why,... Please please help me sort this out its killing me for the past 2 days. Coda 2 is showing me an error
" Warning: include(./includes/header.php): failed to open stream: No such file or directory in - on line 2 Warning: include(): Failed opening './includes/header.php' for inclusion (include_path='.:') in - on line 2 "
init.php code:
<?php
session_start();
$GLOBALS['config'] = array(
'mysql' => array(
'host' => 'localhost',
'username' => 'root',
'password' => 'root',
'db' => 'webAwwards'
),
'remember' => array(
'cookie_name' => 'hash',
'cookie_expire' => 604800
),
'session' => array(
'session_name' => 'user'
)
);
// TODO Remove parenthesis in require once if doesnt work
spl_autoload_register(function($class) {
require_once('classes/' . $class . '.php');
});
require_once('/functions/sanitise.php');
?>
try :
include('../test/header.php');
it works fine in me.
Edit: and if not on your case, try to correct the path of your init.php:
require_once('../core/init.php');
You could try something like:
include $_SERVER['DOCUMENT_ROOT'] .'*/project_name_if_needed*/test/header/';
I don't know if this is recommended, so use with caution.
I had the same issue and finally discovered that OVH deactivates the option allow_url_include on their shared web servers by default. This is a general setting that can not be changed.
The solution is to use something like
require ($_SERVER['DOCUMENT_ROOT'].'/wp-config.php');
as Lucas said.

new DomDocument() do not work with getElementsByTagName('section'); [duplicate]

This question already has answers here:
PHP DOMDocument error handling
(5 answers)
Closed 9 years ago.
I would like to have different outputs if the file is called by Ajax or not.
For that I have this code witch works fine:
/* AJAX check */
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$content = get_content();
die($content);
}
my function for filtering the contend is this:
function get_content(){
//$file = file_get_contents('index.html'); //works better but i get only errors
$dom = new DomDocument();
$dom->loadHTML($_SERVER['REQUEST_URI']); //or $file
$section= $dom->getElementsByTagName('section');
return $section->item(0)->nodeValue;
}
my output is always empty.
Whats wrong here?
!!!I'am not looking for DOMDocument error handling!!!!
What I do for now is:
/* decide what the content should be up here .... */
/* AJAX check */
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
/* if ajax, show only content of the section tag */
$file = file_get_contents($_SERVER['SCRIPT_FILENAME']);
$section = preg_replace("/.*<section[^>]*>|<\/section>.*/si", "", $file);
die($section);
}
/* not ajax, show page.... */
and it seems to work. I do not know it is the best solution because somewhere in this forum I read that its better to realise that with DomDocument().
Any suggestions are welcome?
Here is the html-file:
<!doctype html>
<!-- Determine browser JS free -->
<!-- HTML5 Mobile Boilerplate -->
<!--[if IEMobile 7]><html class="no-js iem7"><![endif]-->
<!--[if (gt IEMobile 7)|!(IEMobile)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<!-- HTML5 Boilerplate -->
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if (IE 7)&!(IEMobile)]><html class="no-js lt-ie9 lt-ie8" lang="en"><![endif]-->
<!--[if (IE 8)&!(IEMobile)]><html class="no-js lt-ie9" lang="en"><![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>title</title>
<link rel="stylesheet" type="text/css" href="../css/style.css">
<link rel="shortcut icon" href="img/base/favicon.html" />
<link rel="apple-touch-icon-precomposed" href="img/base/apple-touch-icon-57x57-precomposed.html" />
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="img/base/apple-touch-icon-72x72-precomposed.html" />
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="img/base/apple-touch-icon-114x114-precomposed.html" />
<script src="/js/libs/modernizr.custom.js"></script>
<!--[if (IE 7)]>
<link rel="stylesheet" href="/css/fallback/icons-ie7.css">
<![endif]-->
</head>
<body >
<section role="main">
<header class="hero-banner">
<img class="resize" src="/img/base/spacer-hero.png" rel="/img/designers/banners/cloe-banner3.jpg" alt="Cloe" />
<noscript><img src="/img/designers/banners/cloe-banner3.jpg" alt="Cloe" /></noscript>
<hgroup>
<h1>Claudia</h1>
<h2 class="text-hl">Designerin</h2>
</hgroup>
</header>
</section>
<footer role="contentinfo">
<p><small>©2013 joe</small></p>
<p><small>Our website uses delicious cookies to improve your experience. We'll assume you're ok with that.</small></p>
</footer>
<!-- jQuery from Google's CDN with local fallback -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="/js/libs/jquery-1.8.3.min.js"><\/script>')</script>
<script src="/js/libs/wfl.js"></script>
<!-- Initialises scripts from plugins.js and helper.js -->
<script src="/js/script.js"></script>
<!-- Google Goggles -->
</body>
</html>
You can turn the errors of by setting internal errors to true:
$doc = new DOMDocument;
$before = libxml_use_internal_errors(true);
$doc->loadHTML($html);
libxml_use_internal_errors($before);
You then won't have the errors logged any longer. In your case most likely you've got display errors enabled which might be okay for development, but on your production server, please switch to error logging otherwise your website would reveal too much data to the outside.
See as well:
PHP DOMDocument error handling

Categories