How to use CURL examples and tutorials

('error-curl.txt'); But you can read the file after the function that create and use the curl ... ::: Network is unreachable] The reason of network is unreachable can be the curl tries to use IPv6 ... [How to debug curl with CURLOPT_STDERR and CURLOPT_VERBOSE] Step 1, enable verbose ... mode in curl curl_setopt($ch, CURLOPT_VERBOSE, true); If the problem is connection timeout, you may

Use a plugin pattern in PHP instead of global variable

call it polymorphism. Its tempting to abuse a global variable in PHP to implement it. Declare ... is a solution I used to solve the global variable issue. [Instead of overwrite global variable, we ... . Using a global variable will be a disaster, the abstractions will leaks everywhere. Here ... can use a plugin] A plugin is an implementation can be plugged into a predefined place. And its

Call to undefined function mysql_connect

The reason of the problem is PHP didn't load php_msql.dll correct. Here is how to solve ... the problem. Print the output of phpinfo and search for Loaded Configuration File, and locate ... the configuration file: Open the file with your editor and search for extension_dir Make sure ... the path is right, usually it should point to ext directory of your PHP installation.

PHP date function

For example, I want date in this format

Use format string "Y-m-d"

preg_match

format. preg_match('/line1\r\ntheme_name:([\s\S]*?)\r\nline3/', $text, $matches); The matches ... Match text between two lines, suppose we have three lines of text line1 theme_name:theme1 ... line3 We want to extract out the theme name, here the "theme1" string. We use windows line ending ... will looks like Array ( [0] => line1 theme_name:theme1 line3 [1] => theme1 )

preg_match_all

Here is a sample html file contains only "p" and "div" tag:

And we want to insert content into the html, we don't want undermine the html structure, we wish to delimit it in terms of html element, not just characters. We also want to know the positions we want to insert the content. We can use PREG_OFFSET_CAPTURE:

Simple PHP performance profiling

One day you found that the page takes almost one minute to load. And it not happened before. You don't know which part of your program get a performance bottleneck. But some complex sql queries looks suspicious.

You want to know how much time elapsed for each of these queries.

Display output of PHP print_r in HTML

Both echo and print_r are widely used in day to day PHP programming, but raw print_r is very unfriendly to HTML display which is the de facto output interface in web developing environment.

Most PHPer may have tried at some moments in their career life to make their own version of a wrapper of print_r to make it HTML friendly. Here are some handy code that I used for my tasks, they are truly great life savers at some particular moments.

Most PHPer may have tried at some moments in their career life to make their own version of a wrapper of print_r to make it HTML friendly. .

How to match domain name with regular expression in PHP

There are many ways to tell whether a request is sent by bot or crawler, one of them is check the user agent string.

Normal user agent only contains information about browser version and platform information. Crawler has some special characteristics.

How to insert Adsense in the middle of content with PHP

When adding Adsense box to your website there are a lot of choices. You can put it on the banner, or the sidebar or inside the content, for the first and second its trivial to do, this post talking about the third one, inside post content, nowadays most publisher choose to put Adsense right inside the content.

Previous Page 1 2 3 ... 5 Next Page