phpcs require alternative syntax in html files - php-5.3

I want to require alternative syntax in controle structure within html files , otherwise, throw error or warning if alternative syntax rules not been respected in whatever instruction .
Below is an example of alternative syntax that should be established:
<?php if (true === $var) : ?>
<h3>Hello world</h3>
<?php else : ?>
<h3>Hello</h3>
<?php endif; ?>
Is there a phpcs sniff which deals with such requirements ? if not , how can we make a customized sniff to check for alternative syntax in html files ?

Related

str_replace and htmlspecialchars not working

OK, I know that what I see is not necessarily what the code says. I got that part figured out. But I have a long list of characters that need to be stored in a database as their html entities rather than as the punctuation marks. I have updated my code to this:
$searchval = array("á","–","—","/"," ","-","...","…","\&","\'","í","\[","\~","\"","\]");
$replaceval = array("\&egrave\;","\&ndash\;","\&mdash\;","\&#47","\&#nbsp\;","\&#hyphen\;","\&hellip\;","\&hellip\;","\&amp\;","\&apos\;","\&igrave\;","\&lbrack\;","\&ntilde\;","\&quot\;","\&rbrack\;");
str_replace($searchval,$replaceval,$fixed);
But the entitiy names are not going into the database.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'most # rig&ht...'
How do I get the entities to go into the database rather than the punctuation marks?
<!DOCTYPE html>
<html>
<body style="margin-left:50px">
<?php
$fixed = "this is al'most right";
echo $fixed;
echo "<br>";
echo "htmlspecialchars: ";
echo htmlspecialchars($fixed, ENT_QUOTES);
echo "<br>";
echo "str_replace: ";
echo str_replace("'", "&apos;", $fixed);
echo "<br>";
?>
</body>
</html>

Parse error: syntax error, unexpected end of file plzz help me find out whats the error?

0){
while ($row=mysqli_fetch_array($res))
{
$Name=$row['Name'];
$Link=$row['Link'];
?>
">
0){
while ($row=mysqli_fetch_array($res))
{
$submenu=$row['submenu'];
?>
Please share a bigger snippet of code. This error usually happens when there is a typing mistake or not closing php tags. Make sure your <?php ?> tags are opening and closing correctly and check if you are using shorthand tags like this <? } ?> If you are using it please avoid that. Also make sure that you are not mixing PHP opening and closing tags with }?> make sure there is a space between php opening and closing tags.

Expression Engine PHP & Embed & entry_id_from

I have the following line in a file that is building up a PHP array and writes it in a txt file on server.:
{exp:channel:entries channel="orders" entry_id_from="{embed:LAST_ID}" sort="desc" dynamic="no"}
AND another file that needs to take an id from database and THIS FILE must be embedded into the ACTION FILE ( the one with the line above ) and the ID to be put into the entry_id_from
LAST_ID file:
<?
include '!mysql.php';
$last_id = #mysql_result(mysql_query('SELECT comanda_id_end FROM output_comenzi ORDER BY id DESC'),0);
if(!$last_id) $last_id = 0;
echo $last_id;
?>
How can I make that the LAST_ID file to get PARSED, take the value and insert it into entry_id_from file? I want to somehow embed The Parsed Mysql File into the ARRay File.
Please help :)
Edited to make this work for PHP on output:
I double checked the EE parse order and it looks like you can make this work with EE parsing on output, but I am not 100% certain.
LAST ID File ('template_group/LAST_ID' EE template). Set to parse PHP on output (per your requirement).
<?
include '!mysql.php';
$last_id = #mysql_result(mysql_query('SELECT comanda_id_end FROM output_comenzi ORDER BY id DESC'),0);
if(!$last_id) $last_id = 0;
?>
// call our embedded template and pass our EE variable forward
{embed="template_group/EXPORT_ACTION_FILE" LAST_ID="<? echo $last_id; ?>"}
Your other file ('template_group/EXPORT_ACTION_FILE' EE template):
{exp:channel:entries channel="orders" entry_id_from="{embed:LAST_ID}" sort="desc" dynamic="no"}

PHP include outside url

When trying to include a php file into another it either does nothing at all (no errors). If i require it will give a useless message
"Failed opening required 'http://example.org.com/xxx.php' (include_path='.:/usr/local/php5/lib/php')
<div id="menu"> <?php include("http://www.sitename.com/menu.php") ?> </div>
The file im trying to include is on the same site and host.
The page im including from is:
root/wiki/skin/index.php (mediawiki)
menu.php is located:
root/menu.php
since mediawiki treats the /wiki/ path as the root i cannot back out with ../../ etc.
What am i doing wrong here? Thanks
Sir, try this:
<div id="menu"> <?php include("../../menu.php") ?> </div>
To include URLs in your PHP project you must have enabled (true) this option:
allow_url_include
in your php.ini configuration. More information you can find here:
http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-include

jHtmlArea href link corrupted on echo?

I have a jHtmlArea as a text input for a web displayed output unfortunately any images or links that are put into the text area are corrupted with a \ before the quotation mark, when echo'd on the output page.
Is there ant way to code this differently?
Input
$text = preg_replace("/\r\n/", '', $_POST[$textIndex]) . PHP_EOL;
echo is
<?php if ($text) : // text ?>
<div><?php echo $text; ?></div>
Found the answer. It's really simple. Just change output to echo stripslashes($text)

Resources