CSS issue when using PHP - php

What is the error in this CSS class?
.ux-row-action-cell .x-grid3-cell-inner {
padding:1px 0 0 0;
}
I don't see any error in ASP.NET, but when I am using the same CSS in PHP, Firebug says "syntax error".

Perhaps your selector is what's causing the issue... Try adding a comma in between:
.ux-row-action-cell, .x-grid3-cell-inner

It would be helpful if we could get a bigger snippet of the code around that line. Static strings would be output the same either way, so possibly a malformed piece of your dynamic code is causing the syntax error. The syntax for that one line is correct.

Related

A weird PHP file in which any instruction is a syntax error

I have a Web application in PHP which when / (or something else) of it is opened in a browser displays the following error in the browser: Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in /var/www/n_environment.php on line 3. The file n_environment.php is loaded with require_once 'n_environment.php'; in index.php. And also from different places. It contains just comments, calls to define (unconditional or guarded by if (!defined) and two assignments of arrays of strings to variables.
I thought maybe it's (indirectly) in a class but not in a method, which indeed PHP prohibits for require_once, but apparently that's not the problem here. If I put anything else as the first instruction, e.g. echo or an assignment, a similar error (with a different offending token) results.
If I comment out everything in the file except the initial <?php, the error changes to unexpected end of file.
And if I also remove the <?php, what I get in the browser is the file content (block comment with code inside) with รข instead of new lines.
What are the possible, most likely reasons for such behaviour? And how to fix it?

Problems using PHP variables with the same CSS selector names in newer PHP versions

I'm working on an e-commerce site as part of an online PHP class at Treehouse.com. I ran into an issue where one of the menu items was displaying incorrectly as can be seen here: http://herkuhleez.com/shirts4mike/
Upon looking for an answer in their forums, another student concluded it was an issue with the newer versions of PHP as the older versions had no display issues with the exact same code as seen here: http://cheetahcandy.com/shirts4mike/
The first example (with the error) is running PHP version 5.4.24 and the second one is running 5.2.17. My localhost server is running 5.5.6 and I have the same error as the first example.
This student however discovered a work around in newer versions by simply changing any php variable names that are the same as the css selector names, at least when the php is written inside a tag's class attribute.
My QUESTION is: Is this a bug in these newer versions of PHP or is this working as intended as some sort of auto-correct function?
EDIT* Here is the forum discussion over at Treehouse: https://teamtreehouse.com/forum/build-a-simple-php-application-adding-active-states-to-the-navigation-php-versions
If you have a look at your CSS on the site with the error, you will notice that your class .section.shirts has the following css on line 605 of style.css
padding-bottom: 42px;
background: #fff
Funnily enough if you take both of those out, it looks exactly the same as the other website.
In addition, the class also has an error in it:
shirts <br /> <b>Notice</b>: Undefined variable: section in <b>/home4/herkuhle/public_html/shirts4mike/inc/header.php</b> on line <b>17</b><br />
I would have a look at header.php on line 17 to see what is causing that.
MORE INFORMATION
EDIT: This question seems to relate to a predefined project available at an educational site. The OP seems to be confused as to why the exact same code fails on some servers, and seems to work others. They were thinking it was something to do with the PHP version. It is more likely as a result of the suppression of warnings server side. To suppress warnings you could simply add:
error_reporting(E_ERROR | E_PARSE);
However; it would be far better to define or test the variable properly [in this case $section] and not simply mask the issue.
Using a PHP variable called $section along with a CSS selector of the same name will work
..Just because you can do something, doesn't mean you should..
Anyway, it is not a CSS error per se, but it certainly doesn't help in this circumstance.
Take note that the error/warning in your code has the word section in it:
<li class="shirts <br /> <b>Notice</b>: Undefined variable: section .....">
Both examples have a CSS style called section.shirts:
.section.shirts {
background: none repeat scroll 0 0 #FFFFFF;
padding-bottom: 42px;
}
As a result of the placement of the error/warning, most browsers will interpret your class as to include any of the words found within the quotes (eg; shirts undefined section etc) and apply them all as styles if found in your CSS. In your version of the page, as a result of the placement of the error, you are applying the styling above. The other site does not have an error/warning with the word section within double quotes inside a class so it does not apply that particular styling.
There is no correlation between PHP variables and CSS selectors (read: There is no conflict between PHP Variables and CSS Selector Names/variables in current, older or dare I say it, future versions of PHP) with the same name unless you generate an error in your resultant HTML in an unfortunate position. In this case, you have done this by creating an error between double quotes inside a class.
Fix your error and your styling will apply as expected. No bug here (other than line 17 in your code :)
Without seeing your code, to fix your error/warning:
[Unlikely] Maybe add a $ in front of section where applicable in your code if it is missing somewhere (like this $section)
Maybe ensure you are defining $section before you test it in your if statements
Maybe Use isset when testing $section if you don't know if it was previously initialized.
So in summary, the word section is rendered inside your HTML within an error/warning and interpreted as part of your CSS class structure as discussed.
Why does it work on older versions of PHP?
If you are wondering why it works in other environments, have you considered that maybe it has nothing to do with the PHP Version - Perhaps in other environments with the same error/warning, they have configured PHP to suppress the display of errors and or warnings.
Without the error, the word section would not appear inside your class; ergo - no style issue.
From the PHP Manual:
Relying on the default value of an uninitialized variable is
problematic in the case of including one file into another which uses
the same variable name. It is also a major security risk with
register_globals turned on. E_NOTICE level error is issued in case of
working with uninitialized variables, however not in the case of
appending elements to the uninitialized array. isset() language
construct can be used to detect if a variable has been already
initialized.
For more information about your particular error, see this previous answer.
Just have a look in your HTML markup and you 'll recognize the following php notice:
<b>Notice</b>: Undefined variable: section in <b>/home4/herkuhle/public_html/shirts4mike/inc/header.php</b> on line <b>17</b>
Just have a look in your header.php file around line 17. Your problem is a follow up of this php notice. Looks like a css class isn 't defined properly.

Parsing CSS using PHP error undefined offset 1

I am trying to parse through css using php I am using a css parser from this link: http://www.phpclasses.org/browse/file/4684.html, but I keep getting this
error message:
Notice: Undefined offset: 1 in C:\wamp\www\Thesis\cssparser-2003-09-20\cssparser.php on line 106
The code I am using is as follows
include_once('cssparser-2003-09-20/cssparser.php');
foreach($html->find('link') as $link)
{
$href = $link->getAttribute('href');
$css = new cssparser();
$css->Parse($href);
echo $css->Get("body","color");
}
This will look for the href attribute and use the attribute from this to grab the css file which should then be parsed through but error above is occurring. Any help would be much appreciated?
Line 106 of cssparser.php says:
list($codekey, $codevalue) = explode(":",$code);
The explode() is generating the Undefined offset error. So that means that the css file getting parsed has in invalid statement somewhere and missing :. The explode can't find any : in $code.
Now this is just an assumption (you didn't provide actual .css file), but the file might have some invalid content, something like this:
.classdefinition {
color #000000;
}
There's a : missing between color and #000000.
I don't think a comment is the problem, as at first look, the class takes care of skipping them.
Try passing the css file through a CSS validator.
If the CSS syntax is OK, then the class has a bug.
Now if we both have the same (latest) version of cssparser.php, a quick patch would be to replace lines 106-109 with:
$arr = explode(":", $code);
if (count($arr) == 2 && strlen(trim($arr[0])) > 0 && strlen(trim($arr[1])) > 0) {
$this->css[$key][trim($arr[0])] = trim($arr[1]);
}
But again, that doesn't guarantee invalid CSS will be parsed correctly and that this class is error free.
And mind that I didn't actually test or worked with the class, all that is suggested here is just by looking at the code you posted and the class code.
Later edit:
At a quick google search, I found PHP-CSS-Parser which looks more complete and robust, and it's hosted on Github (so others could contribute to it).
Another edit:
Also check this answer here, looks simple enough, but as the author says, doesn't handle comments inside selectors.
Hope this helped.

strip_tags not working properly

I am using this in my tpl file , like
{strip_tags({$obj->getfunc()})}
and it gives mes error like syntax error: unrecognized tag:
is anything wrong with the syntax ??
full error message
<b>Fatal error</b>: Smarty error: [in file.tpl line 7]: syntax error: unrecognized tag: strip_tags({$obj->getfunc()
Your code:
strip_tags({$obj->getfunc()})
The problem here is the {} curly braces. I don't know why you thought you needed these, but they're not required.
[edit]
I see you've edited the question/comments to note that you're using Smarty. Now the curly braces make sense.
I guess you started off with just {$obj->getfunc()}, and decided to do strip_tags() on it to prevent hacks.
The {} braces are part of Smarty, so you should only use them this way for the entire block of code. So you need them outside of the `strip_tags() function, and not inside, on the method call as you had it previously.
So instead of this strip_tags({$obj->getfunc()}), you should have something like this:
{strip_tags($obj->getfunc())}
Hope that helps.
[edit 2]
Okay, I'm a PHP dev, not a smarty dev. The code above is valid PHP (not counting the {} braces). But maybe smarty doesn't like that.
I googled and found this page on the Smarty website: http://www.smarty.net/docs/en/language.modifier.strip.tags.tpl
That page gives some specific Smarty syntax for strip_tags, so based on that, it looks like you code should look like this:
{$obj->getfunc()|strip_tags}
I'd run this function not at presentation level but at business logic level.
Replace { from JavaScript code in your template with {literal} and } with {/literal}

PHP eval issue with PHP + HTML code

I've got PHP and HTML code stored in a database table. When I get this data, I need to echo the HTML and process the PHP. I thought I could use eval() for this, which works, if I do this eval("echo 'dlsj'; ?> EVALED "); I get "dlsjEVALED" printed out.
The problem is, I get a fatal error when I run longer scripts. Things like:
Parse error: syntax error, unexpected '<' in /home/content.php(18) : eval()'d code on line 1
Best advice - never store php and html code in your database. And avoid eval() like the plague.
I can't really tell what's wrong with your code, as you haven't provided enough information. But even if I did have some advice, I don't think I could give it in good conscience.
You should redesign your whole application so that it doesn't require storing such things in the database. I can't imagine why it would be necessary.
just right der...........
eval('?>' . $content .'<?php');
You need to re-open php mode after the EVALED. Apparently you have to do this with <? rather than the full <?php.
As a rule eval is to be avoided. But rules are made to be broken. There's a thread at When is eval evil in php? that gives some less dogmatic advice.
Depending on what you want to do, it might be suitable to use a template file that you source, with text that will vary stored in a local variable prior to sourcing the template.
As for storing code to be executed in the DB... this does happen in some frameworks like Drupal to provide convenient extensibility, but then Drupal is pretty thoroughly scoured for security weaknesses.
Also if you're writing self-modifying code then you need to use eval(). Not sure if anyone has done that in php but it would certainly be interesting.
I would guess that you're trying to eval() something that contains an opening <?php tag. And that leads to the error at hand.
$contents = htmlentities($contents);
echo html_entity_decode(eval($contents));

Categories