If you’re server doesn’t allow you to show error in php try the following lines at the near the top of your script.
Try this:
<?php
// Report all PHP errors
error_reporting(E_ALL);
ini_set("display_errors", 1);
If it still doesn’t show up, the web server daemon may not have write permissions to the default logging directory.
function clean_up_xml($xml_string='', $array_of_tags)
{
if (count($array_of_tags) == 0)
{
throw new Exception('Second parameter, must be an array of strings');
}
foreach ($array_of_tags as $tag)
{
// Clean up tags, and trim whitespaces around the tag.
$needle[] = "@[\n\r\t ]*(\<[/]?{$tag}\>)[\n\r\t ]*@";
$replace[] = '$1';
// find tags that don't have CDATA, and wrap them with CDATA
$needle[] = "@\<{$tag}\>(?!\<\!\[CDATA\[)(.*?)\</{$tag}\>@ms";
$replace[] = "<{$tag}><![CDATA[$1]]></{$tag}>";
$xml_string = preg_replace($needle, $replace, $xml_string);
}
return $xml_string;
}
Explanation:
- Remove all spaces, tabs, \r, and \n characters around the desired tag, replace with just the tag itself
- Find all occurances of $tag, but not followed by <![CDATA[, and wrap contents in <![CDATA[ ... ]]>.
Golden tidbit I found while doing some maintenance:
$count = count($some_array);
if($count)
{
if($count > 1)
{
$val = 'PluralText';
}
elseif ($count == 1)
{
$val = 'SingularText';
}
elseif ($language == 'fr')
{
$val = 'PluralText';
}
else
{
$val = 'SingularText';
}
}
else
{
$val = 'None found';
}
could have been just written as
if ( $count = count( $some_array ) )
{
$val = ( $count > 1 ) ? 'PluralText' : 'SingularText';
}
else
{
$val = 'None found';
}
The reason in this example, the first section language code would never be reached.
The program would never reach the “$language” if condition. Allowing us to remove that extra code.
Simplifying the code to the point where it’s easily readable. Some may say that ternary statements are cryptic to read. I agree for the most poart. But when setting a simple value… say setting up initial values.
$value =
(empty($this->getRequestParameter('some_random_parameter'))
?
null
:
$this->getRequestParameter('some_random_parameter');
is better then writing
if (!empty($this->getRequestParameter('some_random_parameter'))
{
$value = $this->getRequestParameter('some_random_parameter');
}
else
{
$value = null;
}
The error is simply this
mysql_quety(...);
If the programmer originally check their code by just running the script, the php parser would have immediately stated that it does not know the function “mysql_quety()”. I’m surprised that this passed the programmers initial inspection.
This leads to the question in the title…
in our code…
<?php
$var = doQuery($something);
however, “doQuery” was never defined. The original programmer never even ran the program after writing it.
Moral of the story, test your code at least by running it.