Saturday, February 23, 2013

PHP ERRORS AND Their Solutions

Fatal error: Call to undefined method domdocument::loadHTML()

 

find and comment the line: extension=php_domxml.dll (make it  ;extension=php_domxml.dll   ) in php.ini file(php configuration file) and restart the apache.






How can I get a post by title in Wordpress? or How to get a post by title in Wordpress?

 

get_page_by_title($post_title, OBJECT, 'Post');
the above code returns the object of the post. it will return single post object even if there 

 

 

plain html check box image

for all those people who are looking for plain html check box image .take the above image.





The URL can't be shown" message on iPad and URL includes unwanted tel tag


people see this error while working with html links on iPad.the telephone detection feature in iPad is the reason for this issue.if u don't need this feature on your site
u can fix this issue simply by copy pasting the following html inside your html head section(i.e. before
tag)






Deprecated: Function ........() is deprecated in ...\xampp..htdocs .....php on line 

 

 

The value of this setting (in latest php versions for e.g. php 5.3.5) may look like below:
error_reporting = E_ALL | E_STRICT
E_STRICT warns about the usage of deprecated functions. If you run an old piece of code on a new/ latest version then, you may get the following error.
Deprecated: Function split() is deprecated in D:\xampp-1.7.4\htdocs \newfile.php on line 5
{split function is deprecated in latest php versions (5.3.0+)}
To avoid this error change the setting as below
error_reporting = E_ALL

 

 

 

 

Strip additional white spaces

 

With UTF8 the “normal” preg_replace doesn’t really work anymore. For some cases we could use the following trick:
$str = utf8_decode($str);
$str = preg_replace('/\s\s+/', ' ', $str);
$str = utf8_encode($str);
A better solution, though, is:
$str = preg_replace('/\s\s+/u', ' ', $str);
With the param “u” it’s compatible with Unicode.

Sort arrays in natural order

$array = array('1.txt', '20.txt', '2.txt', '21.txt');
natsort($array); # sorts by reference (returns boolean $success)

Condition + assignment

If you want to save the extra line for $pos = $this->calcPos()) you need to be aware that extra brackets might be needed. Wrong (if $pos is supposed to hold the position and not the result of the comparison):
if ($pos = $this->calcPos() > 0 && ...) {...}
Correct:
if (($pos = $this->calcPos()) > 0 && $pos < 100) {
    # doSomething
    $pos++;
    # doSomethingElseWithPos
}
Note the extra brackets around $pos. They are necessary – otherwise it will assign the result of the operation $this->calcPos()) > 0 (which is a boolean).

Comparison (default and strict)

Since PHP isn’t type safe you should use strict comparison (===) wherever possible. "+010" == "10.0" is TRUE (!) only with "+010" === "10.0" you will get FALSE. This might be expected in this case – usually it’s not, though. So it is not if (strpos($str, 'hello') == 0) {} but if (strpos($str, 'hello') === 0) {}, for example! What happens in the == case? It will return true in 2 cases: If “hello” is not in the string at all or if it is at the very beginning. But we would only want the second case (and therefore need ===).